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>
This commit is contained in:
@ -672,23 +672,20 @@ static char *username_path_completion(char *ud)
|
||||
*/
|
||||
static NOINLINE unsigned complete_username(const char *ud)
|
||||
{
|
||||
/* Using _r function to avoid pulling in static buffers */
|
||||
char line_buff[256];
|
||||
struct passwd pwd;
|
||||
struct passwd *result;
|
||||
struct passwd *pw;
|
||||
unsigned userlen;
|
||||
|
||||
ud++; /* skip ~ */
|
||||
userlen = strlen(ud);
|
||||
|
||||
setpwent();
|
||||
while (!getpwent_r(&pwd, line_buff, sizeof(line_buff), &result)) {
|
||||
while ((pw = getpwent()) != NULL) {
|
||||
/* Null usernames should result in all users as possible completions. */
|
||||
if (/*!userlen || */ strncmp(ud, pwd.pw_name, userlen) == 0) {
|
||||
add_match(xasprintf("~%s/", pwd.pw_name));
|
||||
if (/*!userlen || */ strncmp(ud, pw->pw_name, userlen) == 0) {
|
||||
add_match(xasprintf("~%s/", pw->pw_name));
|
||||
}
|
||||
}
|
||||
endpwent();
|
||||
endpwent(); /* don't keep password file open */
|
||||
|
||||
return 1 + userlen;
|
||||
}
|
||||
|
Reference in New Issue
Block a user