[BusyBox] my_getpw(u/g)id.....and call for helping to test new id

Tito farmatito at tiscali.it
Sun Aug 29 22:13:09 UTC 2004


On Sunday 29 August 2004 OO:43, you wrote:
Hi, Felipe
> This is a rather small change and would make all the code cleaner.
> Could be something like this:
> 
> $ cat teste2.c
> #include <stdio.h>
> #include <pwd.h>
> #include <sys/types.h>
> #define SIZE_UID_TO_STRING 24 /* We do _know_ this size! */

So if I understand it right the buffer must be at least 24  to hold 
the maximum for uid_t or gid_t?
Maybe i'm not clever enough to understand how you get this result ;-).
Can you please explain it to me?

char *my_getpwuid(long uid,  int flag_exit_on_error)
> {
>         struct passwd *myuser;
	   char uid_string[24];

>         myuser = getpwuid(uid);
>         if (myuser == NULL) {
                 if (flag_exit_on_error == TRUE) {
                         sprintf(uid_string, "%ld", (long)uid);
			return uid_string;				
		 } else {
			  bb_error_msg_and_die("unknown user ID %ld", (long) uid);
		}
>         } else {
                  return  myuser->pw_name;
>         }
> 
         return NULL;
> }
> 

> Felipe Kellermann

Looks good, but the main difference with the design of other libbb functions
is that they do a bb_error_msg_and_die on error,
which is what makes you reduce codesize.
In this case we have to check for NULL two times inside the function
and outside if we need to handle this error .
I would add this  few lines.
I know that the use of the flag is not elegant but i've no better idea at the moment.
test.c attached.

 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test.c
Type: text/x-csrc
Size: 902 bytes
Desc: not available
Url : http://lists.busybox.net/pipermail/busybox/attachments/20040829/4ef4a6e0/attachment.c 


More information about the busybox mailing list