aboutsummaryrefslogtreecommitdiff
path: root/libpwdgrp/pwd_grp.c
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2007-06-18 10:08:27 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2007-06-18 10:08:27 +0000
commit2c91efb7c24da6370810991459ae360029022250 (patch)
treee19858ed06964fc51dbd95b8076ed4cf6e74f338 /libpwdgrp/pwd_grp.c
parent7679145cfa61e41099645bdeecb6a8c2743c6772 (diff)
downloadbusybox-w32-2c91efb7c24da6370810991459ae360029022250.tar.gz
busybox-w32-2c91efb7c24da6370810991459ae360029022250.tar.bz2
busybox-w32-2c91efb7c24da6370810991459ae360029022250.zip
libpwdgrp/pwd_grp.c: allocate local storage on first call, not in bss. -1k bss
function old new delta get_S - 31 +31 bb_internal_getpwnam 38 44 +6 bb_internal_getgrnam 38 44 +6 bb_internal_getgrgid 38 44 +6 ptr_to_statics - 4 +4 static.resultbuf 88 - -88 static.buffer 1024 - -1024 ------------------------------------------------------------------------------ (add/remove: 2/2 grow/shrink: 3/0 up/down: 53/-1112) Total: -1059 bytes
Diffstat (limited to 'libpwdgrp/pwd_grp.c')
-rw-r--r--libpwdgrp/pwd_grp.c123
1 files changed, 96 insertions, 27 deletions
diff --git a/libpwdgrp/pwd_grp.c b/libpwdgrp/pwd_grp.c
index d59fd50bf..4e476f26d 100644
--- a/libpwdgrp/pwd_grp.c
+++ b/libpwdgrp/pwd_grp.c
@@ -53,6 +53,66 @@ static int bb__parsespent(void *sp, char *line);
53#endif 53#endif
54 54
55/**********************************************************************/ 55/**********************************************************************/
56/* We avoid having big global data. */
57
58struct statics {
59 /* Smaller things first */
60 struct passwd getpwuid_resultbuf;
61 struct group getgrgid_resultbuf;
62 struct passwd getpwnam_resultbuf;
63 struct group getgrnam_resultbuf;
64
65 char getpwuid_buffer[PWD_BUFFER_SIZE];
66 char getgrgid_buffer[GRP_BUFFER_SIZE];
67 char getpwnam_buffer[PWD_BUFFER_SIZE];
68 char getgrnam_buffer[GRP_BUFFER_SIZE];
69#if 0
70 struct passwd fgetpwent_resultbuf;
71 struct group fgetgrent_resultbuf;
72 struct spwd fgetspent_resultbuf;
73 char fgetpwent_buffer[PWD_BUFFER_SIZE];
74 char fgetgrent_buffer[GRP_BUFFER_SIZE];
75 char fgetspent_buffer[PWD_BUFFER_SIZE];
76#endif
77#if 0 //ENABLE_USE_BB_SHADOW
78 struct spwd getspuid_resultbuf;
79 struct spwd getspnam_resultbuf;
80 char getspuid_buffer[PWD_BUFFER_SIZE];
81 char getspnam_buffer[PWD_BUFFER_SIZE];
82#endif
83// Not converted - too small to bother
84//pthread_mutex_t mylock = PTHREAD_MUTEX_INITIALIZER;
85//FILE *pwf /*= NULL*/;
86//FILE *grf /*= NULL*/;
87//FILE *spf /*= NULL*/;
88#if 0
89 struct passwd getpwent_pwd;
90 struct group getgrent_gr;
91 char getpwent_line_buff[PWD_BUFFER_SIZE];
92 char getgrent_line_buff[GRP_BUFFER_SIZE];
93#endif
94#if 0 //ENABLE_USE_BB_SHADOW
95 struct spwd getspent_spwd;
96 struct spwd sgetspent_spwd;
97 char getspent_line_buff[PWD_BUFFER_SIZE];
98 char sgetspent_line_buff[PWD_BUFFER_SIZE];
99#endif
100};
101
102static struct statics *ptr_to_statics;
103
104static struct statics *get_S(void)
105{
106 if (!ptr_to_statics)
107 ptr_to_statics = xzalloc(sizeof(*ptr_to_statics));
108 return ptr_to_statics;
109}
110
111/* Always use in this order, get_S() must be called first */
112#define RESULTBUF(name) &((S = get_S())->name##_resultbuf)
113#define BUFFER(name) (S->name##_buffer)
114
115/**********************************************************************/
56/* For the various fget??ent_r funcs, return 116/* For the various fget??ent_r funcs, return
57 * 117 *
58 * 0: success 118 * 0: success
@@ -127,21 +187,23 @@ int fgetspent_r(FILE *__restrict stream, struct spwd *__restrict resultbuf,
127#if 0 187#if 0
128struct passwd *fgetpwent(FILE *stream) 188struct passwd *fgetpwent(FILE *stream)
129{ 189{
130 static char buffer[PWD_BUFFER_SIZE]; 190 struct statics *S;
131 static struct passwd resultbuf; 191 struct passwd *resultbuf = RESULTBUF(fgetpwent);
192 char *buffer = BUFFER(fgetpwent);
132 struct passwd *result; 193 struct passwd *result;
133 194
134 fgetpwent_r(stream, &resultbuf, buffer, sizeof(buffer), &result); 195 fgetpwent_r(stream, resultbuf, buffer, sizeof(BUFFER(fgetpwent)), &result);
135 return result; 196 return result;
136} 197}
137 198
138struct group *fgetgrent(FILE *stream) 199struct group *fgetgrent(FILE *stream)
139{ 200{
140 static char buffer[GRP_BUFFER_SIZE]; 201 struct statics *S;
141 static struct group resultbuf; 202 struct group *resultbuf = RESULTBUF(fgetgrent);
203 char *buffer = BUFFER(fgetgrent);
142 struct group *result; 204 struct group *result;
143 205
144 fgetgrent_r(stream, &resultbuf, buffer, sizeof(buffer), &result); 206 fgetgrent_r(stream, resultbuf, buffer, sizeof(BUFFER(fgetgrent)), &result);
145 return result; 207 return result;
146} 208}
147#endif 209#endif
@@ -150,11 +212,12 @@ struct group *fgetgrent(FILE *stream)
150#if 0 212#if 0
151struct spwd *fgetspent(FILE *stream) 213struct spwd *fgetspent(FILE *stream)
152{ 214{
153 static char buffer[PWD_BUFFER_SIZE]; 215 struct statics *S;
154 static struct spwd resultbuf; 216 struct spwd *resultbuf = RESULTBUF(fgetspent);
217 char *buffer = BUFFER(fgetspent);
155 struct spwd *result; 218 struct spwd *result;
156 219
157 fgetspent_r(stream, &resultbuf, buffer, sizeof(buffer), &result); 220 fgetspent_r(stream, resultbuf, buffer, sizeof(BUFFER(fgetspent)), &result);
158 return result; 221 return result;
159} 222}
160#endif 223#endif
@@ -239,22 +302,24 @@ int sgetspent_r(const char *string, struct spwd *result_buf,
239/* This one has many users */ 302/* This one has many users */
240struct passwd *getpwuid(uid_t uid) 303struct passwd *getpwuid(uid_t uid)
241{ 304{
242 static char buffer[PWD_BUFFER_SIZE]; 305 struct statics *S;
243 static struct passwd resultbuf; 306 struct passwd *resultbuf = RESULTBUF(getpwuid);
307 char *buffer = BUFFER(getpwuid);
244 struct passwd *result; 308 struct passwd *result;
245 309
246 getpwuid_r(uid, &resultbuf, buffer, sizeof(buffer), &result); 310 getpwuid_r(uid, resultbuf, buffer, sizeof(BUFFER(getpwuid)), &result);
247 return result; 311 return result;
248} 312}
249 313
250/* This one has many users */ 314/* This one has many users */
251struct group *getgrgid(gid_t gid) 315struct group *getgrgid(gid_t gid)
252{ 316{
253 static char buffer[GRP_BUFFER_SIZE]; 317 struct statics *S;
254 static struct group resultbuf; 318 struct group *resultbuf = RESULTBUF(getgrgid);
319 char *buffer = BUFFER(getgrgid);
255 struct group *result; 320 struct group *result;
256 321
257 getgrgid_r(gid, &resultbuf, buffer, sizeof(buffer), &result); 322 getgrgid_r(gid, resultbuf, buffer, sizeof(BUFFER(getgrgid)), &result);
258 return result; 323 return result;
259} 324}
260 325
@@ -284,11 +349,12 @@ int getspuid_r(uid_t uid, struct spwd *__restrict resultbuf,
284 * Why it was added, I do not know. */ 349 * Why it was added, I do not know. */
285struct spwd *getspuid(uid_t uid) 350struct spwd *getspuid(uid_t uid)
286{ 351{
287 static char buffer[PWD_BUFFER_SIZE]; 352 struct statics *S;
288 static struct spwd resultbuf; 353 struct spwd *resultbuf = RESULTBUF(getspuid);
354 char *buffer = BUFFER(getspuid);
289 struct spwd *result; 355 struct spwd *result;
290 356
291 getspuid_r(uid, &resultbuf, buffer, sizeof(buffer), &result); 357 getspuid_r(uid, resultbuf, buffer, sizeof(BUFFER(getspuid)), &result);
292 return result; 358 return result;
293} 359}
294#endif 360#endif
@@ -296,33 +362,36 @@ struct spwd *getspuid(uid_t uid)
296/* This one has many users */ 362/* This one has many users */
297struct passwd *getpwnam(const char *name) 363struct passwd *getpwnam(const char *name)
298{ 364{
299 static char buffer[PWD_BUFFER_SIZE]; 365 struct statics *S;
300 static struct passwd resultbuf; 366 struct passwd *resultbuf = RESULTBUF(getpwnam);
367 char *buffer = BUFFER(getpwnam);
301 struct passwd *result; 368 struct passwd *result;
302 369
303 getpwnam_r(name, &resultbuf, buffer, sizeof(buffer), &result); 370 getpwnam_r(name, resultbuf, buffer, sizeof(BUFFER(getpwnam)), &result);
304 return result; 371 return result;
305} 372}
306 373
307/* This one has many users */ 374/* This one has many users */
308struct group *getgrnam(const char *name) 375struct group *getgrnam(const char *name)
309{ 376{
310 static char buffer[GRP_BUFFER_SIZE]; 377 struct statics *S;
311 static struct group resultbuf; 378 struct group *resultbuf = RESULTBUF(getgrnam);
379 char *buffer = BUFFER(getgrnam);
312 struct group *result; 380 struct group *result;
313 381
314 getgrnam_r(name, &resultbuf, buffer, sizeof(buffer), &result); 382 getgrnam_r(name, resultbuf, buffer, sizeof(BUFFER(getgrnam)), &result);
315 return result; 383 return result;
316} 384}
317 385
318#if 0 //ENABLE_USE_BB_SHADOW 386#if 0 //ENABLE_USE_BB_SHADOW
319struct spwd *getspnam(const char *name) 387struct spwd *getspnam(const char *name)
320{ 388{
321 static char buffer[PWD_BUFFER_SIZE]; 389 struct statics *S;
322 static struct spwd resultbuf; 390 struct spwd *resultbuf = RESULTBUF(getspnam);
391 char *buffer = BUFFER(getspnam);
323 struct spwd *result; 392 struct spwd *result;
324 393
325 getspnam_r(name, &resultbuf, buffer, sizeof(buffer), &result); 394 getspnam_r(name, resultbuf, buffer, sizeof(BUFFER(getspnam)), &result);
326 return result; 395 return result;
327} 396}
328#endif 397#endif