diff options
| author | WormHeamer | 2026-01-02 20:38:56 -0500 |
|---|---|---|
| committer | WormHeamer | 2026-01-02 20:38:56 -0500 |
| commit | 7b0cba02d9266eeb71d3ca095afc25ceb1a79e12 (patch) | |
| tree | 59deeae4c4c9f274160df75e02915d5cbdb7212a | |
| parent | b3e19e51d09d0d2cd85f62f6ec2b62b1b03fb7ee (diff) | |
just use realpath() for normalize_path()
| -rw-r--r-- | main.c | 35 |
1 files changed, 6 insertions, 29 deletions
@@ -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) { |
