aboutsummaryrefslogtreecommitdiff
path: root/libpwdgrp
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2015-02-07 21:21:02 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2015-02-07 21:21:02 +0100
commit23cfaab47de7392c1ba7d601a05fb36da3629b28 (patch)
tree228cbefac14b7e60edda2e9314a30bfd43a7e5c5 /libpwdgrp
parent68c048fb23bd8b0831bbd02ec66900b12390cf19 (diff)
downloadbusybox-w32-23cfaab47de7392c1ba7d601a05fb36da3629b28.tar.gz
busybox-w32-23cfaab47de7392c1ba7d601a05fb36da3629b28.tar.bz2
busybox-w32-23cfaab47de7392c1ba7d601a05fb36da3629b28.zip
libpwdgrp: use getpwent() instead of getpwent_r()
function old new delta massage_data_for_non_r_func - 90 +90 bb_internal_getpwent - 69 +69 getXXnam_r 94 162 +68 fill_bounds 131 128 -3 deluser_main 355 310 -45 complete_username 123 78 -45 getXXnam 163 90 -73 massage_data_for_r_func 103 - -103 bb_internal_getpwent_r 121 - -121 ------------------------------------------------------------------------------ (add/remove: 2/2 grow/shrink: 1/5 up/down: 227/-407) Total: -163 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'libpwdgrp')
-rw-r--r--libpwdgrp/pwd_grp.c58
1 files changed, 43 insertions, 15 deletions
diff --git a/libpwdgrp/pwd_grp.c b/libpwdgrp/pwd_grp.c
index 90647e9d3..7ec704ee4 100644
--- a/libpwdgrp/pwd_grp.c
+++ b/libpwdgrp/pwd_grp.c
@@ -336,6 +336,22 @@ static int massage_data_for_r_func(struct passdb *db,
336 return errno; 336 return errno;
337} 337}
338 338
339static void* massage_data_for_non_r_func(struct passdb *db, char *buf)
340{
341 if (!buf)
342 return NULL;
343
344 free(db->malloced);
345 /* We enlarge buf and move string data up, freeing space
346 * for struct passwd/group/spwd at the beginning. This way,
347 * entire result of getXXnam is in a single malloced block.
348 * This enables easy creation of xmalloc_getpwnam() API.
349 */
350 db->malloced = buf = xrealloc(buf, db->size_of + S.string_size);
351 memmove(buf + db->size_of, buf, S.string_size);
352 return convert_to_struct(db, buf + db->size_of, buf);
353}
354
339/****** getXXnam/id_r */ 355/****** getXXnam/id_r */
340 356
341static int FAST_FUNC getXXnam_r(const char *name, uintptr_t db_and_field_pos, 357static int FAST_FUNC getXXnam_r(const char *name, uintptr_t db_and_field_pos,
@@ -372,6 +388,7 @@ int FAST_FUNC getspnam_r(const char *name, struct spwd *struct_buf, char *buffer
372} 388}
373#endif 389#endif
374 390
391#ifdef UNUSED
375/****** getXXent_r */ 392/****** getXXent_r */
376 393
377static int FAST_FUNC getXXent_r(uintptr_t db_idx, char *buffer, size_t buflen, 394static int FAST_FUNC getXXent_r(uintptr_t db_idx, char *buffer, size_t buflen,
@@ -400,17 +417,39 @@ int FAST_FUNC getpwent_r(struct passwd *struct_buf, char *buffer, size_t buflen,
400 *result = struct_buf; 417 *result = struct_buf;
401 return getXXent_r(0, buffer, buflen, result); 418 return getXXent_r(0, buffer, buflen, result);
402} 419}
420#endif
421
422/****** getXXent */
423
424static void* FAST_FUNC getXXent(uintptr_t db_idx)
425{
426 char *buf;
427 struct passdb *db = &get_S()->db[db_idx];
428
429 if (!db->fp) {
430 db->fp = fopen_for_read(db->filename);
431 if (!db->fp) {
432 return NULL;
433 }
434 close_on_exec_on(fileno(db->fp));
435 }
436
437 buf = parse_common(db->fp, db, /*no search key:*/ NULL, -1);
438 return massage_data_for_non_r_func(db, buf);
439}
440
441struct passwd* FAST_FUNC getpwent(void)
442{
443 return getXXent(0);
444}
403 445
404/****** getXXnam/id */ 446/****** getXXnam/id */
405 447
406static void* FAST_FUNC getXXnam(const char *name, unsigned db_and_field_pos) 448static void* FAST_FUNC getXXnam(const char *name, unsigned db_and_field_pos)
407{ 449{
408 char *buf; 450 char *buf;
409 void *result;
410 struct passdb *db = &get_S()->db[db_and_field_pos >> 2]; 451 struct passdb *db = &get_S()->db[db_and_field_pos >> 2];
411 452
412 result = NULL;
413
414 if (!db->fp) { 453 if (!db->fp) {
415 db->fp = fopen_for_read(db->filename); 454 db->fp = fopen_for_read(db->filename);
416 if (!db->fp) { 455 if (!db->fp) {
@@ -420,18 +459,7 @@ static void* FAST_FUNC getXXnam(const char *name, unsigned db_and_field_pos)
420 } 459 }
421 460
422 buf = parse_common(db->fp, db, name, db_and_field_pos & 3); 461 buf = parse_common(db->fp, db, name, db_and_field_pos & 3);
423 if (buf) { 462 return massage_data_for_non_r_func(db, buf);
424 free(db->malloced);
425 /* We enlarge buf and move string data up, freeing space
426 * for struct passwd/group/spwd at the beginning. This way,
427 * entire result of getXXnam is in a single malloced block.
428 * This enables easy creation of xmalloc_getpwnam() API.
429 */
430 db->malloced = buf = xrealloc(buf, db->size_of + S.string_size);
431 memmove(buf + db->size_of, buf, S.string_size);
432 result = convert_to_struct(db, buf + db->size_of, buf);
433 }
434 return result;
435} 463}
436 464
437struct passwd* FAST_FUNC getpwnam(const char *name) 465struct passwd* FAST_FUNC getpwnam(const char *name)