Skip to content

Instantly share code, notes, and snippets.

@tkroman
Created March 10, 2019 10:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tkroman/f08b6ac0fcef7e2d713ab7bc3dff7029 to your computer and use it in GitHub Desktop.
Save tkroman/f08b6ac0fcef7e2d713ab7bc3dff7029 to your computer and use it in GitHub Desktop.
cross-platform home dir in pure C
#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