Created
February 6, 2015 22:08
-
-
Save sposterkil/6cce2633c12ff9fe0554 to your computer and use it in GitHub Desktop.
C snippet to print working directory and effective/real user
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
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