diff options
author | merakor <cem@ckyln.com> | 2020-05-15 14:05:14 +0000 |
---|---|---|
committer | merakor <cem@ckyln.com> | 2020-05-15 14:05:14 +0000 |
commit | 994b2432c5415ab8d3df1c6414b2be57c272d62e (patch) | |
tree | bc4a93485aa633489902e424c04a25cfec95d4c7 /bin | |
parent | e2112a9f0220af7d85df974e6d6e714d8ec97609 (diff) | |
download | cpt-994b2432c5415ab8d3df1c6414b2be57c272d62e.tar.gz |
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
Diffstat (limited to 'bin')
-rw-r--r-- | bin/kiss-readlink.c | 8 |
1 files changed, 8 insertions, 0 deletions
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 <stdio.h> #include <stdlib.h> +#include <libgen.h> #include <string.h> 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 <file>\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); |