aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar sin <sin@2f30.org>2014-10-22 14:22:55 +0100
committerGravatar sin <sin@2f30.org>2014-10-22 14:22:55 +0100
commit75143cd93ec82eb1346eefa955ed42f189d6f449 (patch)
treeceb9b4264c732eb127f64b3a115d6c7f19d96ab3
parentabd301333da81b72070fbb575dcd0824d3af038e (diff)
downloadnnn-75143cd93ec82eb1346eefa955ed42f189d6f449.tar.gz
Add xdirname() to avoid quirks with dirname(3)
-rw-r--r--noice.c20
1 files changed, 17 insertions, 3 deletions
diff --git a/noice.c b/noice.c
index b7f3ba0..71e4897 100644
--- a/noice.c
+++ b/noice.c
@@ -108,16 +108,30 @@ xstrdup(const char *s)
}
char *
-xrealpath(const char *pathname)
+xrealpath(const char *path)
{
char *p;
- p = realpath(pathname, NULL);
+ p = realpath(path, NULL);
if (p == NULL)
printerr(1, "realpath");
return p;
}
+char *
+xdirname(const char *path)
+{
+ char *p, *tmp;
+
+ /* Some implementations of dirname(3) may modify `path' */
+ tmp = xstrdup(path);
+ p = dirname(tmp);
+ free(tmp);
+ if (p == NULL)
+ printerr(1, "dirname");
+ return p;
+}
+
void
spawn(const char *file, const char *arg)
{
@@ -533,7 +547,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);