aboutsummaryrefslogtreecommitdiff
path: root/libbb
diff options
context:
space:
mode:
authorvda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277>2006-12-01 21:34:20 +0000
committervda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277>2006-12-01 21:34:20 +0000
commit47d1391520c2d1aaf56b375c23abca34291281ba (patch)
tree70be5c3624b5a9ead8ae771f0cfbc2da5f6815df /libbb
parentc1c772f690cf909f3546ad3f43c9e6ee785ee72c (diff)
downloadbusybox-w32-47d1391520c2d1aaf56b375c23abca34291281ba.tar.gz
busybox-w32-47d1391520c2d1aaf56b375c23abca34291281ba.tar.bz2
busybox-w32-47d1391520c2d1aaf56b375c23abca34291281ba.zip
passwd: made smaller by ~130 bytes. size can go negative
if current trend will continue ;) git-svn-id: svn://busybox.net/trunk/busybox@16747 69ca8d6d-28ef-0310-b511-8ec308f3f277
Diffstat (limited to 'libbb')
-rw-r--r--libbb/bb_pwd.c68
1 files changed, 33 insertions, 35 deletions
diff --git a/libbb/bb_pwd.c b/libbb/bb_pwd.c
index 48a5c1539..b5125b0f4 100644
--- a/libbb/bb_pwd.c
+++ b/libbb/bb_pwd.c
@@ -12,6 +12,35 @@
12#include <assert.h> 12#include <assert.h>
13#include "libbb.h" 13#include "libbb.h"
14 14
15 /*
16 * if bufsize is > 0 char *buffer cannot be set to NULL.
17 * If idname is not NULL it is written on the static
18 * allocated buffer (and a pointer to it is returned).
19 * if idname is NULL, id as string is written to the static
20 * allocated buffer and NULL is returned.
21 * if bufsize is = 0 char *buffer can be set to NULL.
22 * If idname exists a pointer to it is returned,
23 * else NULL is returned.
24 * if bufsize is < 0 char *buffer can be set to NULL.
25 * If idname exists a pointer to it is returned,
26 * else an error message is printed and the program exits.
27 */
28
29/* internal function for bb_getpwuid and bb_getgrgid */
30static char * bb_getug(char *buffer, char *idname, long id, int bufsize, char prefix)
31{
32 if (bufsize > 0 ) {
33 assert(buffer!=NULL);
34 if(idname) {
35 return safe_strncpy(buffer, idname, bufsize);
36 }
37 snprintf(buffer, bufsize, "%ld", id);
38 } else if (bufsize < 0 && !idname) {
39 bb_error_msg_and_die("unknown %cid %ld", prefix, id);
40 }
41 return idname;
42}
43
15 /* Hacked by Tito Ragusa (c) 2004 <farmatito@tiscali.it> to make it more 44 /* Hacked by Tito Ragusa (c) 2004 <farmatito@tiscali.it> to make it more
16 * flexible : 45 * flexible :
17 * 46 *
@@ -84,49 +113,18 @@ char * bb_getpwuid(char *name, long uid, int bufsize)
84{ 113{
85 struct passwd *myuser = getpwuid(uid); 114 struct passwd *myuser = getpwuid(uid);
86 115
87 return bb_getug(name, (myuser) ? 116 return bb_getug(name, myuser ? myuser->pw_name : (char *)myuser,
88 myuser->pw_name : (char *)myuser , uid, bufsize, 'u'); 117 uid, bufsize, 'u');
89}
90
91 /*
92 * if bufsize is > 0 char *buffer cannot be set to NULL.
93 * If idname is not NULL it is written on the static
94 * allocated buffer (and a pointer to it is returned).
95 * if idname is NULL, id as string is written to the static
96 * allocated buffer and NULL is returned.
97 * if bufsize is = 0 char *buffer can be set to NULL.
98 * If idname exists a pointer to it is returned,
99 * else NULL is returned.
100 * if bufsize is < 0 char *buffer can be set to NULL.
101 * If idname exists a pointer to it is returned,
102 * else an error message is printed and the program exits.
103 */
104
105/* internal function for bb_getpwuid and bb_getgrgid */
106char * bb_getug(char *buffer, char *idname, long id, int bufsize, char prefix)
107{
108 if(bufsize > 0 ) {
109 assert(buffer!=NULL);
110 if(idname) {
111 return safe_strncpy(buffer, idname, bufsize);
112 }
113 snprintf(buffer, bufsize, "%ld", id);
114 } else if(bufsize < 0 && !idname) {
115 bb_error_msg_and_die("unknown %cid %ld", prefix, id);
116 }
117 return idname;
118} 118}
119 119
120unsigned long get_ug_id(const char *s, 120unsigned long get_ug_id(const char *s,
121 long (*__bb_getxxnam)(const char *)) 121 long (*__bb_getxxnam)(const char *))
122{ 122{
123 unsigned long r; 123 unsigned long r;
124 char *p;
125 124
126 r = strtoul(s, &p, 10); 125 r = bb_strtoul(s, NULL, 10);
127 if (*p || (s == p)) { 126 if (errno)
128 r = __bb_getxxnam(s); 127 r = __bb_getxxnam(s);
129 }
130 128
131 return r; 129 return r;
132} 130}