Move start_stop_daemon to debianutils.
[oweals/busybox.git] / coreutils / whoami.c
index 7fd5d01b29dde2446e141de739895e69b1f062cd..f93034d3a3b860c8b8863cfa17303ee9a490e937 100644 (file)
@@ -1,3 +1,4 @@
+/* vi: set sw=4 ts=4: */
 /*
  * Mini whoami implementation for busybox
  *
  *
  */
 
-#include "internal.h"
-#include <stdio.h>
-#include <pwd.h>
+/* BB_AUDIT SUSv3 N/A -- Matches GNU behavior. */
 
-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";
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include "busybox.h"
 
-extern int whoami_main(int argc, char **argv) {
-       struct passwd *pw;
+extern int whoami_main(int argc, char **argv)
+{
+       char user[9];
        uid_t uid;
 
-       if (argc > 1) usage (whoami_usage);
+       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);
+       uid = geteuid();
+       if (my_getpwuid(user, uid)) {
+               puts(user);
+               bb_fflush_stdout_and_exit(EXIT_SUCCESS);
+       }
+       bb_error_msg_and_die("cannot find username for UID %u", (unsigned) uid);
 }