+/* vi: set sw=4 ts=4: */
/*
* Mini whoami implementation for busybox
*
*
*/
-#include "internal.h"
-#include <stdio.h>
-#include <pwd.h>
-
-static const char whoami_usage[] = "whoami\n\n"
-"Print the user name associated with the current effective user id.\n"
-"Same as id -un.\n";
+/* BB_AUDIT SUSv3 N/A -- Matches GNU behavior. */
-extern int whoami_main(int argc, char **argv) {
- struct passwd *pw;
- uid_t uid;
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include "busybox.h"
- if (argc > 1) usage (whoami_usage);
+extern int whoami_main(int argc, char **argv)
+{
+ if (argc > 1)
+ bb_show_usage();
- uid = geteuid ();
- pw = getpwuid (uid);
- if (pw) {
- puts (pw->pw_name);
- exit (TRUE);
- }
- fprintf (stderr, "%s: cannot find username for UID %u\n", argv[0], (unsigned) uid);
- exit (FALSE);
+ puts(bb_getpwuid(NULL, geteuid(), -1));
+ /* exits on error */
+ bb_fflush_stdout_and_exit(EXIT_SUCCESS);
}