diff --git a/rpmio/macro.c b/rpmio/macro.c index b81b03c860..2994c18a01 100644 --- a/rpmio/macro.c +++ b/rpmio/macro.c @@ -6,6 +6,7 @@ #include #include #include +#include #ifdef HAVE_SCHED_GETAFFINITY #include #endif @@ -1306,23 +1307,9 @@ 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 (!strcmp(buf, "")) { - buf = rstrcat(&buf, "."); - } else { - /* strip trailing / */ - size_t l = strlen(buf); - if (l > 1 && buf[l-1] == '/') - buf[l-1] = '\0'; - if ((b = strrchr(buf, '/')) != NULL) - if (b == buf) - /* keep root dir */ - buf[1] = '\0'; - else - *b = '\0'; - else - strcpy(buf, "."); - } - b = buf; + b = xstrdup(dirname(buf)); + free(buf); + buf = b; } else if (rstreq("shrink", me->name)) { /* * shrink body by removing all leading and trailing whitespaces and