summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWormHeamer2026-01-02 20:38:56 -0500
committerWormHeamer2026-01-02 20:38:56 -0500
commit7b0cba02d9266eeb71d3ca095afc25ceb1a79e12 (patch)
tree59deeae4c4c9f274160df75e02915d5cbdb7212a
parentb3e19e51d09d0d2cd85f62f6ec2b62b1b03fb7ee (diff)
just use realpath() for normalize_path()
-rw-r--r--main.c35
1 files changed, 6 insertions, 29 deletions
diff --git a/main.c b/main.c
index 6ea99cd..35fffa6 100644
--- a/main.c
+++ b/main.c
@@ -1035,35 +1035,12 @@ TxtLoc ins_newline(TxtLoc l) {
}
static Str normalize_path(Str s) {
- char pwd[8192];
- if (s.n > 0 && s.s[0] != '/') {
- if (!getcwd(pwd, sizeof(pwd))) {
- return (Str) { 0, 0 };
- }
- Str d = str_from_cstr(pwd);
- str_catc(&d, '/', &e.scratch);
- str_cat(&d, s, &e.scratch);
- s = d;
- }
- DYNARR(Str) bits = { 0 };
- while (s.n > 0) {
- Cut c = str_cut(s, '/');
- if (str_eql(c.head, S(".."))) {
- if (bits.n > 0) bits.n--;
- } else if (str_eql(c.head, S("."))) {
- /* do nothing */
- } else if (c.head.n > 0) {
- DA_APUSH(&bits, &e.scratch, c.head);
- }
- s = c.tail;
- }
- Str path = S("/");
- for (u32 i = 0; i < bits.n; i++) {
- str_cat(&path, bits.v[i], &e.scratch);
- if (i + 1 < bits.n)
- str_catc(&path, '/', &e.scratch);
- }
- return path;
+ Arena m = e.scratch;
+ char *p = realpath(str_to_cstr(s, &e.scratch), NULL);
+ e.scratch = m;
+ s = str_dup(str_from_cstr(p), &e.scratch);
+ free(p);
+ return s;
}
static void build_file(Str path, int debugp) {