aboutsummaryrefslogtreecommitdiffhomepage
path: root/c
diff options
context:
space:
mode:
authorlemon <lsof@mailbox.org>2026-03-05 18:17:35 +0100
committerlemon <lsof@mailbox.org>2026-03-05 18:17:35 +0100
commitbc415887ad22d3fa64632c85ad147546d47652a5 (patch)
tree0203eacdc58365423d7cf9c5e10f36772fe97cbd /c
parent1ec29c2bb4350d09ee34b8eff53b9974fcc0a81f (diff)
cpp: #include".." shouldn't look in working directory
Diffstat (limited to 'c')
-rw-r--r--c/lex.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/c/lex.c b/c/lex.c
index 6099539..459aecd 100644
--- a/c/lex.c
+++ b/c/lex.c
@@ -1786,12 +1786,14 @@ ppinclude(struct lexer *lx, const struct span *span0)
expecteol(lx, "include");
joinspan(&span.ex, tk.span.ex);
if (tk.t == TKPPHDRQ) {
- /* 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;
+ if (tk.s[0] == '/') {
+ /* try 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;
+ }
/* try relative to current file's directory */
base = getfilename(lx->fileid, 0);