Skip to content

Commit

Permalink
Use dirname (3) instead of our own code
Browse files Browse the repository at this point in the history
  • Loading branch information
ffesti committed Mar 5, 2024
1 parent cbff994 commit 225f33d
Showing 1 changed file with 4 additions and 17 deletions.
21 changes: 4 additions & 17 deletions rpmio/macro.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <stdarg.h>
#include <pthread.h>
#include <errno.h>
#include <libgen.h>
#ifdef HAVE_SCHED_GETAFFINITY
#include <sched.h>
#endif
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 225f33d

Please sign in to comment.