diff options
| author | Peter Geissler <peter@haxx.in> | 2026-08-28 15:02:49 +0200 |
|---|---|---|
| committer | Peter Geissler <peter@haxx.in> | 2026-08-28 15:02:49 +0200 |
| commit | 22e70baa7172e8487913cceae3d3ec89bbe40627 (patch) | |
| tree | cd067b59109b829e423995ee10d02f30392ff47a /include | |
| parent | ctrl_d_exits: Ctrl-D at a prompt, where the tty cannot do it (diff) | |
| download | slosh-22e70baa7172e8487913cceae3d3ec89bbe40627.tar.gz slosh-22e70baa7172e8487913cceae3d3ec89bbe40627.tar.xz slosh-22e70baa7172e8487913cceae3d3ec89bbe40627.zip | |
path: an absolute path does not always start with a slash
`include "C:/themes/t.kdl"` on Windows did not fail to find the file. It
found a different one, or rather looked for it: absoluteness was tested
as `path[0] == '/'`, a drive letter is not that, so the path was read as
relative and joined to the including file's directory. The result was
cannot open C:/Users/you/cfgA/C:/Users/you/cfgB/t.kdl
which at least says what happened. A layout's `cwd="C:/srv/api"` took
the same turn through path_resolve() and said nothing at all -- the pane
started in the wrong directory, which is the failure this file's own
header comment is about.
Windows spells absolute three ways and all three now count: rooted on
the current drive (`\dir`), rooted on a named one (`C:\dir`, `C:/dir`),
and a UNC share. A drive letter has to be followed by a separator to
qualify, because `C:file` is relative to the current directory *of that
drive* -- a real thing, and not one we can resolve for anyone.
Windows-only, deliberately. `C:` is an ordinary file name on POSIX and a
path beginning with one is relative there, so reading it as a drive
would break the platform that works in order to fix the one that does
not.
Diffstat (limited to 'include')
| -rw-r--r-- | include/slosh.h | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/include/slosh.h b/include/slosh.h index e1ab08b..793e32c 100644 --- a/include/slosh.h +++ b/include/slosh.h @@ -104,6 +104,11 @@ char *screen_dump_json(screen_t *s); /* ---- paths -------------------------------------------------------------- */ +/* Whether a path stands on its own. A leading `/` everywhere; on Windows also + * a drive (`C:\dir`, `C:/dir`), a drive-relative root (`\dir`) and a UNC + * share. Drive letters are read as such only on Windows, because `C:` is an + * ordinary file name on POSIX. */ +bool path_is_absolute(const char *path); /* Expand a leading `~`, using `buf` when it has to. Returns `path` itself when * there is nothing to do, so `buf` only has to outlive the result's use. */ const char *path_expand(const char *path, char *buf, size_t cap); |
