aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorPeter Geissler <peter@haxx.in>2026-08-28 15:04:28 +0200
committerPeter Geissler <peter@haxx.in>2026-08-28 15:09:18 +0200
commit6f8bdf838b82c0c3326993a741985840dc130af6 (patch)
treee3cca1f71709761deca4422bc3d597b7916e76e5 /include
parentpath: an absolute path does not always start with a slash (diff)
downloadslosh-6f8bdf838b82c0c3326993a741985840dc130af6.tar.gz
slosh-6f8bdf838b82c0c3326993a741985840dc130af6.tar.xz
slosh-6f8bdf838b82c0c3326993a741985840dc130af6.zip
path: a directory ends at either separator on Windows
Two places split a path by hand, both with strrchr(path, '/'), both falling back to "." when there was none: include_path() in config.c and watch_config() in server.c. On Windows "none" is the ordinary case. `SLOSH_CONFIG=C:\Users\you\slosh\config.kdl` is how a person writes it, and a path that has been near a native API comes back all backslashes whatever it started as. So an include resolved against "." -- `cannot open ./themes/t.kdl` -- and, worse and quietly, the config watcher watched "." too. Not the config's directory: the current directory of whatever started the session. Hot reload did not fail, it watched somewhere else and waited. Saving your config did nothing at all, with no error to go looking for. The default path escaped this by accident. slosh builds it as `C:\Users\you/.config/slosh/config.kdl` -- mixed, because a literal joined to $HOME always is -- and that one embedded '/' is what strrchr found. It worked for the path slosh writes and not for the one a user does. Both callers now use path_dir(), which learns to stop at a backslash too, and server.c takes path_base() for the other half rather than keeping its own copy of the arithmetic. Windows-only: a backslash is a legal character in a POSIX file name, and splitting on it there would invent a directory out of a file called `a\b`. path_dir() also keeps the separator when what is left would be a bare drive, because `C:\config.kdl` lives in `C:\` and `C:` names the current directory on drive C, which is a different place. Verified on the Windows box with a fully backslashed SLOSH_CONFIG: --check passes, the include loads, and editing the config reloads the running session. Watching a second directory is still unreliable; that is the watcher's own bug and the next commit.
Diffstat (limited to 'include')
-rw-r--r--include/slosh.h4
1 files changed, 3 insertions, 1 deletions
diff --git a/include/slosh.h b/include/slosh.h
index 793e32c..e624bda 100644
--- a/include/slosh.h
+++ b/include/slosh.h
@@ -119,8 +119,10 @@ const char *path_expand(const char *path, char *buf, size_t cap);
const char *path_resolve(const char *path, const char *base, char *buf,
size_t cap);
/* The directory part of a path: the base `path_resolve` wants. `.` when there
- * is no `/` in it. */
+ * is no separator in it. On Windows a backslash separates too. */
const char *path_dir(const char *path, char *buf, size_t cap);
+/* The name part: the other half of `path_dir`, pointing into `path`. */
+const char *path_base(const char *path);
/* The inverse of `path_resolve` for writing one back out: a path under `base`
* relative to it, `.` for `base` itself, and anything not under it unchanged.
* Points into `path` or a literal, so it needs no buffer. */