summaryrefslogtreecommitdiffstats
path: root/misc-utils/rename.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-14 19:33:32 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-14 19:33:32 +0000
commit8bb05ac73a5b448b339ce0bc8d396c82c459b47f (patch)
tree1fdda006866bca20d41cb206767ea5241e36852f /misc-utils/rename.c
parentAdding debian version 2.39.3-11. (diff)
downloadutil-linux-8bb05ac73a5b448b339ce0bc8d396c82c459b47f.tar.xz
util-linux-8bb05ac73a5b448b339ce0bc8d396c82c459b47f.zip
Merging upstream version 2.40.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'misc-utils/rename.c')
-rw-r--r--misc-utils/rename.c12
1 files changed, 4 insertions, 8 deletions
diff --git a/misc-utils/rename.c b/misc-utils/rename.c
index 04e61ed..9ab3869 100644
--- a/misc-utils/rename.c
+++ b/misc-utils/rename.c
@@ -28,6 +28,7 @@ for i in $@; do N=`echo "$i" | sed "s/$FROM/$TO/g"`; mv "$i" "$N"; done
#include <errno.h>
#include <getopt.h>
#include <fcntl.h>
+#include <libgen.h>
#include <unistd.h>
#include <termios.h>
#include <sys/types.h>
@@ -58,12 +59,7 @@ static char *find_initial_replace(char *from, char *to, char *orig)
/* We only want to search in the final path component. Don't
include the final '/' in that component; if `from` is empty,
we want it to first match after the '/', not before. */
- search_start = strrchr(orig, '/');
-
- if (search_start == NULL)
- search_start = orig;
- else
- search_start++;
+ search_start = basename(orig);
}
return strstr(search_start, from);
@@ -270,8 +266,8 @@ static void __attribute__((__noreturn__)) usage(void)
fputs(_(" -o, --no-overwrite don't overwrite existing files\n"), out);
fputs(_(" -i, --interactive prompt before overwrite\n"), out);
fputs(USAGE_SEPARATOR, out);
- printf(USAGE_HELP_OPTIONS(21));
- printf(USAGE_MAN_TAIL("rename(1)"));
+ fprintf(out, USAGE_HELP_OPTIONS(21));
+ fprintf(out, USAGE_MAN_TAIL("rename(1)"));
exit(EXIT_SUCCESS);
}