[BusyBox] my_getpw(u/g)id.....and call for helping to test new id
Felipe Kellermann
stdfk at terra.com.br
Sun Aug 29 18:43:49 UTC 2004
On Sun, 29 Aug 2004 3:18pm -0000, Tito wrote:
> > Tested `ps', `top', `id' and `ls'. Didn't test `tar' (as I have other
> > ideas here). Sorry for sending such a big diff.
> hi,
> maybe this could be a solution for post 1.0, but I don't think Erik will
> apply this right now.
Hi Tito,
OK, I'm only proposing a solution. ;-)
> As you say there is also the issue of freeing the memory correctly and
> therefore more code changes to do.
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! */
char *my_getpwuid(long uid, char *buf)
{
struct passwd *myuser;
char *ret = NULL;
myuser = getpwuid(uid);
if (myuser == NULL) {
if (buf != NULL)
(void)sprintf(buf, "%ld", (long)uid);
} else {
ret = myuser->pw_name;
}
return ret;
}
/* example snippet */
int
main(int argc, char *argv[])
{
char *p;
char buf[SIZE_UID_TO_STRING];
p = my_getpwuid(atoi(argv[1]), buf);
if (p == NULL) {
puts("unknown uid!");
p = buf;
} /* else { strdup `p' when needed } */
printf("p = `%s'\n", p);
return 0;
}
$ teste2 1000
p = `felipekellermann'
$ teste2 102314
unknown uid!
p = `102314'
> IMHO this my_getpw*id stuff should be removed at all in the future.
> Would like to hear Erik's opinion about that...........
My opinion is that it was apparently made to save some bits of code, so
the more we use it (the more ``generic'' it is), the more text we save.
--
Felipe Kellermann
More information about the busybox
mailing list