From 994b2432c5415ab8d3df1c6414b2be57c272d62e Mon Sep 17 00:00:00 2001 From: merakor Date: Fri, 15 May 2020 14:05:14 +0000 Subject: kiss-readlink: canonicalize directories if files do not exist. kiss-readlink will no longer fail if the targeted symlink doesn't exist. This is similar to how 'readlink -f' works. The previous behaviour was similar to 'readlink -e' from coreutils, i.e it wanted all targets to exist. FossilOrigin-Name: 80e435c92f9269b7eeff2140f57ef4b1fa675d139c4a598621eda6dbbbf2111c --- bin/kiss-readlink.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/bin/kiss-readlink.c b/bin/kiss-readlink.c index 04426f0..279e1b9 100644 --- a/bin/kiss-readlink.c +++ b/bin/kiss-readlink.c @@ -4,11 +4,15 @@ // This is basically a 'readlink -f' command. #include #include +#include #include int main(int argc, char *argv[]) { char buf[512]; + char bname[512]; + strcpy(bname, "/"); + strcat(bname, (basename(argv[1]))); if (argc != 2 || strcmp(argv[1], "--help") == 0) { printf("usage: %s \n", argv[0]); @@ -16,8 +20,12 @@ int main(int argc, char *argv[]) { } if (!realpath(argv[1], buf)) { + + if (!realpath(dirname(argv[1]), buf)) { perror("realpath"); return(1); + } + strcat(buf, bname); } printf("%s\n", buf); -- cgit v1.2.3