cpt

[ARCHIVED] Carbs Packaging Tools
git clone git://git.ckyln.com/~cem/cpt.git
Log | Files | Refs | README | LICENSE

commit b098110b5c878cd72dee80d9997f6d4376875794
parent 3e412fe4c8e5d07719064bf2fa7674ed433c883b
Author: Cem Keylan <cem@ckyln.com>
Date:   Fri, 15 May 2020 17:05:15 +0300

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.

Diffstat:
Mbin/kiss-readlink.c | 8++++++++
1 file changed, 8 insertions(+), 0 deletions(-)

diff --git 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);