]> Sergey Matveev's repositories - nnn.git/commitdiff
Add xdirname() to avoid quirks with dirname(3)
authorsin <sin@2f30.org>
Wed, 22 Oct 2014 13:22:55 +0000 (14:22 +0100)
committersin <sin@2f30.org>
Wed, 22 Oct 2014 13:22:55 +0000 (14:22 +0100)
noice.c

diff --git a/noice.c b/noice.c
index b7f3ba08f1a311108dc0125a94d4c11c2ea093d3..71e4897b6881259e3277468b39bb36f5d4d097fe 100644 (file)
--- 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);