diff options
author | Joseph Hunkeler <jhunkeler@gmail.com> | 2020-05-07 01:01:30 -0400 |
---|---|---|
committer | Joseph Hunkeler <jhunkeler@gmail.com> | 2020-05-07 01:01:30 -0400 |
commit | e2470a89c3cd542b9c2a1e63ed0d78e0f39bed68 (patch) | |
tree | d3986f864073fc0c9a6ddf3df9373be2ca072a0d /scripts/realpath.c | |
parent | f7e076b77c15de441f8e1008a30518c653c3974d (diff) | |
download | spmc-e2470a89c3cd542b9c2a1e63ed0d78e0f39bed68.tar.gz |
Add realpath.c (Darwin is so great)
Diffstat (limited to 'scripts/realpath.c')
-rw-r--r-- | scripts/realpath.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/scripts/realpath.c b/scripts/realpath.c new file mode 100644 index 0000000..15504a0 --- /dev/null +++ b/scripts/realpath.c @@ -0,0 +1,28 @@ +#include <stdlib.h> +#include <stdio.h> +#include <errno.h> + +/** + * Apple loves being different. There's no `realpath` program on MacOS + * @param argc + * @param argv + * @return + */ +int main(int argc, char *argv[]) { + char *path; + + if (argc < 2) { + fprintf(stderr, "usage: %s filename\n", argv[0]); + return 1; + } + + path = realpath(argv[1], NULL); + if (path) { + puts(path); + free(path); + } else { + perror(argv[1]); + } + + return errno; +}
\ No newline at end of file |