From 3ad98187cc64a88d2d31d181d10bef5eef6274b7 Mon Sep 17 00:00:00 2001 From: Florian Festi Date: Tue, 5 Mar 2024 13:47:02 +0100 Subject: [PATCH] Use basename (3) for the %basename macro --- rpmio/macro.c | 5 +---- tests/rpmmacro.at | 10 ++++++++++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/rpmio/macro.c b/rpmio/macro.c index c270eeea5..22e340fc0 100644 --- a/rpmio/macro.c +++ b/rpmio/macro.c @@ -1301,10 +1301,7 @@ static void doFoo(rpmMacroBuf mb, rpmMacroEntry me, ARGV_t argv, size_t *parsed) if (rstreq("basename", me->name)) { buf = xstrdup(argv[1]); - if ((b = strrchr(buf, '/')) == NULL) - b = buf; - else - b++; + b = basename(buf); } else if (rstreq("dirname", me->name)) { buf = xstrdup(argv[1]); b = dirname(buf); diff --git a/tests/rpmmacro.at b/tests/rpmmacro.at index 6d460dd7e..8c6e965f2 100644 --- a/tests/rpmmacro.at +++ b/tests/rpmmacro.at @@ -373,6 +373,11 @@ runroot rpm --eval "%dirname /foo" runroot rpm --eval "%dirname /foo/" runroot rpm --eval "%dirname /foo/foobar" runroot rpm --eval "%dirname /foo/foobar/" +runroot rpm --eval "%basename /foo/foobar" +runroot rpm --eval "%basename /foo/foobar/" +runroot rpm --eval "%basename /" +runroot rpm --eval "%basename foobar/" +runroot rpm --eval "%basename foobar" runroot rpm --define '%xxx /hello/%%%%/world' --eval '%{dirname:%xxx}' runroot rpm --eval "%{uncompress}" runroot rpm --eval "%{uncompress:}" @@ -403,6 +408,11 @@ runroot rpm --eval "%verbose foo" / /foo /foo +foobar +foobar +/ +foobar +foobar /hello/%% bar