Update the lash shell (hopefully the last time...) so things like
[oweals/busybox.git] / logname.c
index 5c8275ab4f868720a2b5b273d4eb9c90313e9a2a..0924b24712628d4e644a472e2ac68ed8d4b497a7 100644 (file)
--- a/logname.c
+++ b/logname.c
@@ -1,3 +1,4 @@
+/* vi: set sw=4 ts=4: */
 /*
  * Mini logname implementation for busybox
  *
  *
  */
 
-#include "internal.h"
 #include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include "busybox.h"
 
-static const char logname_usage[] = "logname\n\n"
-"Print the name of the current user.\n";
+extern int logname_main(int argc, char **argv)
+{
+       char user[9];
 
-extern int logname_main(int argc, char **argv) {
-       char *cp;
+       if (argc > 1)
+               show_usage();
 
-       if (argc > 1) usage (logname_usage);
-
-       cp = getlogin ();
-       if (cp) {
-               puts (cp);
-               exit (TRUE);
-       }
-       fprintf (stderr, "%s: no login name\n", argv[0]);
-       exit (FALSE);
+       my_getpwuid(user, geteuid());
+       if (*user) {
+               puts(user);
+               return EXIT_SUCCESS;
+       }
+       error_msg_and_die("no login name");
 }