diff options
author | lostd <lostd@2f30.org> | 2014-10-22 17:02:15 +0300 |
---|---|---|
committer | lostd <lostd@2f30.org> | 2014-10-22 17:02:15 +0300 |
commit | 36cf4136b5ec5ddc1e84b426e1992b599efbe6ae (patch) | |
tree | 653a608a009ce6156d27adf359585722a792be14 /noice.c | |
parent | 577e0284a11f675b7b9845da7e3a8006905b4fcf (diff) | |
download | noice-36cf4136b5ec5ddc1e84b426e1992b599efbe6ae.tar.gz |
Add xdirname() again and give dirname(3) another chance
Diffstat (limited to 'noice.c')
-rw-r--r-- | noice.c | 21 |
1 files changed, 20 insertions, 1 deletions
@@ -118,6 +118,25 @@ xrealpath(const char *path) return p; } +char * +xdirname(const char *path) +{ + char *p, *tmp; + + /* Some implementations of dirname(3) may modify `path' and some + * return a pointer inside `path` and we cannot free(3) the + * original string if we lose track of it. */ + tmp = xstrdup(path); + p = dirname(tmp); + free(tmp); + if (p == NULL) + printerr(1, "dirname"); + + /* Make sure this is a malloc(3)-ed string */ + p = xstrdup(p); + return p; +} + void spawn(const char *file, const char *arg) { @@ -532,7 +551,7 @@ nochange: if (strcmp(path, "/") == 0) { goto nochange; } else { - dir = dirname(path); + dir = xdirname(path); tmp = xmalloc(strlen(dir) + 1); strlcpy(tmp, dir, strlen(dir) + 1); free(path); |