From: Joel Rosdahl Date: Thu, 8 Aug 2013 16:05:30 +0000 (+0200) Subject: Handle some dirname() special cases as expected X-Git-Tag: v3.1.10~25 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d3eef28469d49f514a0b6e32888c85840a2b8d8f;p=thirdparty%2Fccache.git Handle some dirname() special cases as expected --- diff --git a/test/test_util.c b/test/test_util.c index 10478baa7..afa457ae6 100644 --- a/test/test_util.c +++ b/test/test_util.c @@ -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 3b472def2..93d5a618f 100644 --- 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 {