[BusyBox-cvs] CVS update of busybox/coreutils (whoami.c)

Erik Andersen andersen at codepoet.org
Thu Aug 26 22:36:03 UTC 2004


    Date: Thursday, August 26, 2004 @ 16:36:03
  Author: andersen
    Path: /var/cvs/busybox/coreutils

Modified: whoami.c (1.22 -> 1.23)

Tito writes:

Hi,
I've fixed also the issue of whoami cutting down usernames.
This time I cannot send a diff because i don't know if my previous patches will be applied
or not, so I send in the whole file.
The changes I've made don't affect size but ensure that usernames of whatever lenght
are correctly displayed.
root at localhost:/dev/pts/3:/root/Desktop/busybox/coreutils# size whoami_orig.o
   text    data     bss     dec     hex filename
    102       0       0     102      66 whoami_orig.o
root at localhost:/dev/pts/3:/root/Desktop/busybox/coreutils# size whoami.o
   text    data     bss     dec     hex filename
     93       0       0      93      5d whoami.o

This should be applied even if the other patches aren't as this matches the behaviour of the  GNU whoami.

Thanks in advance,
Ciao,
Tito


Index: busybox/coreutils/whoami.c
diff -u busybox/coreutils/whoami.c:1.22 busybox/coreutils/whoami.c:1.23
--- busybox/coreutils/whoami.c:1.22	Thu Aug 26 16:18:57 2004
+++ busybox/coreutils/whoami.c	Thu Aug 26 16:36:02 2004
@@ -26,18 +26,20 @@
 #include <stdlib.h>
 #include <unistd.h>
 #include "busybox.h"
+#include "pwd_.h"
+#include "grp_.h"
 
 extern int whoami_main(int argc, char **argv)
 {
-	char user[9];
+	struct passwd *p;
 	uid_t uid;
-
+	
 	if (argc > 1)
 		bb_show_usage();
 
 	uid = geteuid();
-	if (my_getpwuid(user, uid, sizeof(user))) {
-		puts(user);
+	if((p = getpwuid(uid))!=NULL) {
+		puts(p->pw_name);
 		bb_fflush_stdout_and_exit(EXIT_SUCCESS);
 	}
 	bb_error_msg_and_die("cannot find username for UID %u", (unsigned) uid);



More information about the busybox-cvs mailing list