Skip to content

Instantly share code, notes, and snippets.

@sposterkil
Created February 6, 2015 22:08
Show Gist options
  • Save sposterkil/6cce2633c12ff9fe0554 to your computer and use it in GitHub Desktop.
Save sposterkil/6cce2633c12ff9fe0554 to your computer and use it in GitHub Desktop.
C snippet to print working directory and effective/real user
char path[PATH_MAX];
// We use this getpwuid(geteuid()) construct instead of cuserid()
// for portability (Works on OS X and Linux)
printf("I ran in the directory %s, as effective user %s, real user %s.\n",
getcwd(path, PATH_MAX),
getpwuid(geteuid())->pw_name,
getpwuid(getuid())->pw_name);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment