*
*/
-#include "internal.h"
+#include "busybox.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";
+#include <stdlib.h>
+#include <unistd.h>
extern int whoami_main(int argc, char **argv)
{
- struct passwd *pw;
- uid_t uid;
+ char user[9];
+ uid_t uid = geteuid();
if (argc > 1)
usage(whoami_usage);
- uid = geteuid();
- pw = getpwuid(uid);
- if (pw) {
- puts(pw->pw_name);
- exit(TRUE);
+ my_getpwuid(user, uid);
+ if (*user) {
+ puts(user);
+ return EXIT_SUCCESS;
}
- fprintf(stderr, "%s: cannot find username for UID %u\n", argv[0],
- (unsigned) uid);
- exit(FALSE);
+ error_msg_and_die("cannot find username for UID %u", (unsigned) uid);
}