Created
July 24, 2017 18:15
-
-
Save cboin/87f3f2837ad8d1160fc8da585362eae8 to your computer and use it in GitHub Desktop.
Get the absolute path of given files
This file contains 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
#include <stdio.h> | |
#include <stdlib.h> | |
#include <limits.h> | |
#include <unistd.h> | |
/* | |
* Darwin 16.6.0 Darwin Kernel Version 16.6.0 | |
* $ make apof | |
* author: Clément Boin | |
*/ | |
int main(int argc, char **argv) | |
{ | |
if (argc < 2) { | |
fprintf(stderr, "usage: %s FILE[..]\n", argv[0]); | |
return EXIT_FAILURE; | |
} | |
char *cwd = (char *) malloc(sizeof(char) * PATH_MAX); | |
if (cwd == NULL) { | |
perror("cwd: malloc failed"); | |
return EXIT_FAILURE; | |
} | |
size_t i; | |
for (i = 1; i < argc; ++i) { | |
if (getcwd(cwd, (sizeof(char) * PATH_MAX)) != NULL) { | |
printf("%s/%s\n", cwd, argv[i]); | |
} else { | |
perror("getcwd failed"); | |
return EXIT_FAILURE; | |
} | |
} | |
return EXIT_SUCCESS; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment