diff options
| -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) { |
