logo

utils-std

Collection of commonly available Unix tools git clone https://anongit.hacktivis.me/git/utils-std.git
commit: 0133f3fd11fb4e6e83b6da99217c46a1aee0cfb1
parent 7880a97b0cbb63e898f02c194c3aefd978da2fa4
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Mon,  4 Nov 2024 02:13:12 +0100

cmd/ln: use basename() instead of strrchr()

This allows to have commands like `ln -s ../bar/*/ ./` working.

Diffstat:

Mcmd/ln.c5++---
1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/cmd/ln.c b/cmd/ln.c @@ -14,6 +14,7 @@ #include <assert.h> #include <errno.h> #include <fcntl.h> // linkat, AT_SYMLINK_FOLLOW +#include <libgen.h> // basename #include <limits.h> // PATH_MAX #include <stdbool.h> #include <stdio.h> // fprintf @@ -198,9 +199,7 @@ main(int argc, char *argv[]) for(int i = 0; i < argc - 1; i++) { char *src = argv[i]; - - char *src_sep = strrchr(src, '/'); - char *src_basename = src_sep != NULL ? src_sep + 1 : src; + char *src_basename = basename(src); if(snprintf(target, PATH_MAX, "%s/%s", dest, src_basename) < 0) {