From 7b0cba02d9266eeb71d3ca095afc25ceb1a79e12 Mon Sep 17 00:00:00 2001 From: WormHeamer Date: Fri, 2 Jan 2026 20:38:56 -0500 Subject: just use realpath() for normalize_path() --- main.c | 35 ++++++----------------------------- 1 file 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) { -- cgit v1.2.3