diff --git a/rpmio/macro.c b/rpmio/macro.c index 88546e7d0..c270eeea5 100644 --- a/rpmio/macro.c +++ b/rpmio/macro.c @@ -6,6 +6,7 @@ #include #include #include +#include #ifdef HAVE_SCHED_GETAFFINITY #include #endif @@ -1306,9 +1307,7 @@ static void doFoo(rpmMacroBuf mb, rpmMacroEntry me, ARGV_t argv, size_t *parsed) b++; } else if (rstreq("dirname", me->name)) { buf = xstrdup(argv[1]); - if ((b = strrchr(buf, '/')) != NULL) - *b = '\0'; - b = buf; + b = dirname(buf); } else if (rstreq("shrink", me->name)) { /* * shrink body by removing all leading and trailing whitespaces and diff --git a/tests/rpmmacro.at b/tests/rpmmacro.at index 47a13ef2b..6d460dd7e 100644 --- a/tests/rpmmacro.at +++ b/tests/rpmmacro.at @@ -364,6 +364,15 @@ runroot rpm --eval "%{dirname:dir}" runroot rpm --eval "%{dirname dir}" runroot rpm --eval "%dirname" runroot rpm --eval "%dirname dir" +runroot rpm --eval "%dirname /" +runroot rpm --eval "%dirname ./" +runroot rpm --eval "%dirname .." +runroot rpm --eval "%dirname ../" +runroot rpm --eval "%dirname ../foo" +runroot rpm --eval "%dirname /foo" +runroot rpm --eval "%dirname /foo/" +runroot rpm --eval "%dirname /foo/foobar" +runroot rpm --eval "%dirname /foo/foobar/" runroot rpm --define '%xxx /hello/%%%%/world' --eval '%{dirname:%xxx}' runroot rpm --eval "%{uncompress}" runroot rpm --eval "%{uncompress:}" @@ -381,10 +390,19 @@ runroot rpm --eval "%shrink %%%%" runroot rpm --eval "%verbose foo" ], [0], -[ -dir -dir -dir +[. +. +. +. +/ +. +. +. +.. +/ +/ +/foo +/foo /hello/%% bar