aboutsummaryrefslogtreecommitdiffhomepage
path: root/c
diff options
context:
space:
mode:
authorlemon <lsof@mailbox.org>2025-11-22 10:24:12 +0100
committerlemon <lsof@mailbox.org>2025-11-22 10:24:12 +0100
commitc2f9d128ecd15c9f285426b4e7b9bc2cd3d53732 (patch)
tree743cde39225e04adfeae733dca9fa1bab0fe79e2 /c
parent654dde3b3f2fafddb9139cc53af0633689b1d2b7 (diff)
lex: #include ".." should also look in working directory
Diffstat (limited to 'c')
-rw-r--r--c/lex.c36
1 files changed, 17 insertions, 19 deletions
diff --git a/c/lex.c b/c/lex.c
index e016a6a..afadffc 100644
--- a/c/lex.c
+++ b/c/lex.c
@@ -1597,25 +1597,23 @@ ppinclude(struct lexer *lx, const struct span *span0)
const char *base, *end;
joinspan(&span.ex, tk.span.ex);
if (tk.t == TKPPHDRQ) {
- if (tk.s[0] == '/') {
- /* absolute path */
- xbgrow(&path, tk.len + 1);
- memcpy(path, tk.s, tk.len);
- path[tk.len] = 0;
- if (tryinclude(lx, &span, path)) return;
- goto NotFound;
- } else {
- /* build relative path */
- base = getfilename(lx->fileid);
- for (end = base; *end != 0; ++end) {}
- for (--end; *end != '/' && end != base; --end) {}
- if (*end == '/') ++end;
- xbgrow(&path, end - base + tk.len + 1);
- memcpy(path, base, end - base);
- memcpy(path + (end - base), tk.s, tk.len);
- path[end - base + tk.len] = 0;
- if (tryinclude(lx, &span, path)) return;
- }
+ /* try raw path: absolute or relative to working dir */
+ xbgrow(&path, tk.len + 1);
+ memcpy(path, tk.s, tk.len);
+ path[tk.len] = 0;
+ if (tryinclude(lx, &span, path)) return;
+ if (tk.s[0] == '/') goto NotFound;
+
+ /* try relative to current file's directory */
+ base = getfilename(lx->fileid);
+ for (end = base; *end != 0; ++end) {}
+ for (--end; *end != '/' && end != base; --end) {}
+ if (*end == '/') ++end;
+ xbgrow(&path, end - base + tk.len + 1);
+ memcpy(path, base, end - base);
+ memcpy(path + (end - base), tk.s, tk.len);
+ path[end - base + tk.len] = 0;
+ if (tryinclude(lx, &span, path)) return;
}
/* try system paths */
for (struct inclpaths *p = cinclpaths; p; p = p->next) {