]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Handle some dirname() special cases as expected
authorJoel Rosdahl <joel@rosdahl.net>
Thu, 8 Aug 2013 16:05:30 +0000 (18:05 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Thu, 8 Aug 2013 16:05:30 +0000 (18:05 +0200)
test/test_util.c
util.c

index 10478baa7d6eac753ec3574144c8a57ca159b7fc..afa457ae6e46c865fb790b215e7fb1040a38175a 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2010, 2012 Joel Rosdahl
+ * Copyright (C) 2010, 2012-2013 Joel Rosdahl
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License as published by the Free
@@ -36,6 +36,8 @@ TEST(basename)
 TEST(dirname)
 {
        CHECK_STR_EQ_FREE2(".", dirname("foo.c"));
+       CHECK_STR_EQ_FREE2(".", dirname(""));
+       CHECK_STR_EQ_FREE2("/", dirname("/"));
        CHECK_STR_EQ_FREE2("dir1/dir2", dirname("dir1/dir2/foo.c"));
        CHECK_STR_EQ_FREE2("/dir", dirname("/dir/foo.c"));
        CHECK_STR_EQ_FREE2("dir1/dir2", dirname("dir1/dir2/"));
diff --git a/util.c b/util.c
index 3b472def20976e81f688593ebd66586eb6962d02..93d5a618fb179c059197ae0c92e16d6d6815714c 100644 (file)
--- a/util.c
+++ b/util.c
@@ -692,7 +692,9 @@ dirname(char *s)
 #endif
        if (p < p2)
                p = p2;
-       if (p) {
+       if (p == s) {
+               return s;
+       } else if (p) {
                *p = 0;
                return s;
        } else {