Created
March 10, 2019 10:11
-
-
Save tkroman/f08b6ac0fcef7e2d713ab7bc3dff7029 to your computer and use it in GitHub Desktop.
cross-platform home dir in pure C
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 <stdlib.h> | |
#include <stdio.h> | |
#include <string.h> | |
#define PATH_LEN 256 | |
int main(void) | |
{ | |
char path[PATH_LEN]; | |
FILE *pipe; | |
if(!(pipe = popen("scala -e 'print(sys.props(\"user.home\"))'", "r"))) | |
{ | |
fprintf(stderr, "Error\n"); | |
exit(1); | |
} | |
memset(path, 0, PATH_LEN); | |
fgets(path, PATH_LEN-1, pipe); | |
printf("User directory: %s\n", path); | |
pclose(pipe); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment