Last active
April 18, 2019 03:47
-
-
Save geoff-nixon/1f23957288d371b75a2e to your computer and use it in GitHub Desktop.
Portable realpath(1) / readlink -f, written is portable POSIX C.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // So, this used to be a really terrible shell script I wrote years ago. | |
| // Its was buggy in all kinds of corner cases, If you really need it, check | |
| // out the revision history. Otherwise, if you have a functioning C compiler, | |
| // you *really* should be using the system's realpath(3) function to do this. | |
| // Here's a bare-bones version. To compile, just: `cc realpath.c -o realpath` | |
| #include <stdio.h> | |
| #include <stdlib.h> | |
| int main(int argc, char *argv[]) { | |
| char *symlinkpath = argv[1]; | |
| char *actualpath = realpath(symlinkpath, NULL); | |
| if (actualpath != NULL) { | |
| realpath(symlinkpath, actualpath); | |
| printf("%s", actualpath); | |
| free(actualpath); | |
| return 0; | |
| } else { | |
| return 1; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.