diff options
Diffstat (limited to 'whoami.c')
-rw-r--r-- | whoami.c | 27 |
1 files changed, 16 insertions, 11 deletions
@@ -1,3 +1,4 @@ | |||
1 | /* vi: set sw=4 ts=4: */ | ||
1 | /* | 2 | /* |
2 | * Mini whoami implementation for busybox | 3 | * Mini whoami implementation for busybox |
3 | * | 4 | * |
@@ -24,21 +25,25 @@ | |||
24 | #include <pwd.h> | 25 | #include <pwd.h> |
25 | 26 | ||
26 | static const char whoami_usage[] = "whoami\n\n" | 27 | static const char whoami_usage[] = "whoami\n\n" |
27 | "Print the user name associated with the current effective user id.\n" | 28 | "Print the user name associated with the current effective user id.\n" |
28 | "Same as id -un.\n"; | ||
29 | 29 | ||
30 | extern int whoami_main(int argc, char **argv) { | 30 | "Same as id -un.\n"; |
31 | |||
32 | extern int whoami_main(int argc, char **argv) | ||
33 | { | ||
31 | struct passwd *pw; | 34 | struct passwd *pw; |
32 | uid_t uid; | 35 | uid_t uid; |
33 | 36 | ||
34 | if (argc > 1) usage (whoami_usage); | 37 | if (argc > 1) |
38 | usage(whoami_usage); | ||
35 | 39 | ||
36 | uid = geteuid (); | 40 | uid = geteuid(); |
37 | pw = getpwuid (uid); | 41 | pw = getpwuid(uid); |
38 | if (pw) { | 42 | if (pw) { |
39 | puts (pw->pw_name); | 43 | puts(pw->pw_name); |
40 | exit (TRUE); | 44 | exit(TRUE); |
41 | } | 45 | } |
42 | fprintf (stderr, "%s: cannot find username for UID %u\n", argv[0], (unsigned) uid); | 46 | fprintf(stderr, "%s: cannot find username for UID %u\n", argv[0], |
43 | exit (FALSE); | 47 | (unsigned) uid); |
48 | exit(FALSE); | ||
44 | } | 49 | } |