diff options
author | Denis Vlasenko | 2006-12-01 21:34:20 +0000 |
---|---|---|
committer | Denis Vlasenko | 2006-12-01 21:34:20 +0000 |
commit | becd8c538cc689460dca83ecc92222969059c5f4 (patch) | |
tree | 70be5c3624b5a9ead8ae771f0cfbc2da5f6815df /libbb/bb_pwd.c | |
parent | 732268fe69739411c8e1373e688381253a04efe6 (diff) | |
download | busybox-becd8c538cc689460dca83ecc92222969059c5f4.zip busybox-becd8c538cc689460dca83ecc92222969059c5f4.tar.gz |
passwd: made smaller by ~130 bytes. size can go negative
if current trend will continue ;)
Diffstat (limited to 'libbb/bb_pwd.c')
-rw-r--r-- | libbb/bb_pwd.c | 68 |
1 files changed, 33 insertions, 35 deletions
diff --git a/libbb/bb_pwd.c b/libbb/bb_pwd.c index 48a5c15..b5125b0 100644 --- a/libbb/bb_pwd.c +++ b/libbb/bb_pwd.c @@ -12,6 +12,35 @@ #include <assert.h> #include "libbb.h" + /* + * if bufsize is > 0 char *buffer cannot be set to NULL. + * If idname is not NULL it is written on the static + * allocated buffer (and a pointer to it is returned). + * if idname is NULL, id as string is written to the static + * allocated buffer and NULL is returned. + * if bufsize is = 0 char *buffer can be set to NULL. + * If idname exists a pointer to it is returned, + * else NULL is returned. + * if bufsize is < 0 char *buffer can be set to NULL. + * If idname exists a pointer to it is returned, + * else an error message is printed and the program exits. + */ + +/* internal function for bb_getpwuid and bb_getgrgid */ +static char * bb_getug(char *buffer, char *idname, long id, int bufsize, char prefix) +{ + if (bufsize > 0 ) { + assert(buffer!=NULL); + if(idname) { + return safe_strncpy(buffer, idname, bufsize); + } + snprintf(buffer, bufsize, "%ld", id); + } else if (bufsize < 0 && !idname) { + bb_error_msg_and_die("unknown %cid %ld", prefix, id); + } + return idname; +} + /* Hacked by Tito Ragusa (c) 2004 <farmatito@tiscali.it> to make it more * flexible : * @@ -84,49 +113,18 @@ char * bb_getpwuid(char *name, long uid, int bufsize) { struct passwd *myuser = getpwuid(uid); - return bb_getug(name, (myuser) ? - myuser->pw_name : (char *)myuser , uid, bufsize, 'u'); -} - - /* - * if bufsize is > 0 char *buffer cannot be set to NULL. - * If idname is not NULL it is written on the static - * allocated buffer (and a pointer to it is returned). - * if idname is NULL, id as string is written to the static - * allocated buffer and NULL is returned. - * if bufsize is = 0 char *buffer can be set to NULL. - * If idname exists a pointer to it is returned, - * else NULL is returned. - * if bufsize is < 0 char *buffer can be set to NULL. - * If idname exists a pointer to it is returned, - * else an error message is printed and the program exits. - */ - -/* internal function for bb_getpwuid and bb_getgrgid */ -char * bb_getug(char *buffer, char *idname, long id, int bufsize, char prefix) -{ - if(bufsize > 0 ) { - assert(buffer!=NULL); - if(idname) { - return safe_strncpy(buffer, idname, bufsize); - } - snprintf(buffer, bufsize, "%ld", id); - } else if(bufsize < 0 && !idname) { - bb_error_msg_and_die("unknown %cid %ld", prefix, id); - } - return idname; + return bb_getug(name, myuser ? myuser->pw_name : (char *)myuser, + uid, bufsize, 'u'); } unsigned long get_ug_id(const char *s, long (*__bb_getxxnam)(const char *)) { unsigned long r; - char *p; - r = strtoul(s, &p, 10); - if (*p || (s == p)) { + r = bb_strtoul(s, NULL, 10); + if (errno) r = __bb_getxxnam(s); - } return r; } |