+/* vi: set sw=4 ts=4: */
/*
* Mini logname implementation for busybox
*
*
*/
-#include "internal.h"
+#include "busybox.h"
#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.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)
+ usage(logname_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\n");
}