diff options
Diffstat (limited to 'src/whoami.c')
-rw-r--r-- | src/whoami.c | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/src/whoami.c b/src/whoami.c index e563dcf20..1b0c3cdb6 100644 --- a/src/whoami.c +++ b/src/whoami.c @@ -61,6 +61,7 @@ main (int argc, char **argv) { struct passwd *pw; uid_t uid; + uid_t NO_UID = -1; initialize_main (&argc, &argv); set_program_name (argv[0]); @@ -81,8 +82,9 @@ main (int argc, char **argv) usage (EXIT_FAILURE); } + errno = 0; uid = geteuid (); - pw = getpwuid (uid); + pw = (uid == NO_UID && errno ? NULL : getpwuid (uid)); if (pw) { puts (pw->pw_name); |