libpwdgrp: another code shrink
function old new delta massage_data_for_r_func - 110 +110 bb_internal_getpwent_r 173 100 -73 getXXnam_r 176 95 -81 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 0/2 up/down: 110/-154) Total: -44 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
parent
5acf1346b4
commit
db4d1051ca
@ -316,27 +316,19 @@ static void *convert_to_struct(struct passdb *db,
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/****** getXXnam/id_r */
|
static int massage_data_for_r_func(struct passdb *db,
|
||||||
|
|
||||||
static int FAST_FUNC getXXnam_r(const char *name, uintptr_t db_and_field_pos,
|
|
||||||
char *buffer, size_t buflen,
|
char *buffer, size_t buflen,
|
||||||
void *result)
|
void **result,
|
||||||
|
char *buf)
|
||||||
{
|
{
|
||||||
void *struct_buf = *(void**)result;
|
void *result_buf = *result;
|
||||||
char *buf;
|
*result = NULL;
|
||||||
struct passdb *db = &get_S()->db[db_and_field_pos >> 2];
|
|
||||||
|
|
||||||
*(void**)result = NULL;
|
|
||||||
buf = parse_file(db, name, 0 /*db_and_field_pos & 3*/);
|
|
||||||
/* "db_and_field_pos & 3" is commented out since so far we don't implement
|
|
||||||
* getXXXid_r() functions which would use that to pass 2 here */
|
|
||||||
if (buf) {
|
if (buf) {
|
||||||
size_t size = S.tokenize_end - buf;
|
if (S.string_size > buflen) {
|
||||||
if (size > buflen) {
|
|
||||||
errno = ERANGE;
|
errno = ERANGE;
|
||||||
} else {
|
} else {
|
||||||
memcpy(buffer, buf, size);
|
memcpy(buffer, buf, S.string_size);
|
||||||
*(void**)result = convert_to_struct(db, buffer, struct_buf);
|
*result = convert_to_struct(db, buffer, result_buf);
|
||||||
}
|
}
|
||||||
free(buf);
|
free(buf);
|
||||||
}
|
}
|
||||||
@ -347,6 +339,22 @@ static int FAST_FUNC getXXnam_r(const char *name, uintptr_t db_and_field_pos,
|
|||||||
return errno;
|
return errno;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/****** getXXnam/id_r */
|
||||||
|
|
||||||
|
static int FAST_FUNC getXXnam_r(const char *name, uintptr_t db_and_field_pos,
|
||||||
|
char *buffer, size_t buflen,
|
||||||
|
void *result)
|
||||||
|
{
|
||||||
|
char *buf;
|
||||||
|
struct passdb *db = &get_S()->db[db_and_field_pos >> 2];
|
||||||
|
|
||||||
|
buf = parse_file(db, name, 0 /*db_and_field_pos & 3*/);
|
||||||
|
/* "db_and_field_pos & 3" is commented out since so far we don't implement
|
||||||
|
* getXXXid_r() functions which would use that to pass 2 here */
|
||||||
|
|
||||||
|
return massage_data_for_r_func(db, buffer, buflen, result, buf);
|
||||||
|
}
|
||||||
|
|
||||||
int FAST_FUNC getpwnam_r(const char *name, struct passwd *struct_buf,
|
int FAST_FUNC getpwnam_r(const char *name, struct passwd *struct_buf,
|
||||||
char *buffer, size_t buflen,
|
char *buffer, size_t buflen,
|
||||||
struct passwd **result)
|
struct passwd **result)
|
||||||
@ -369,15 +377,12 @@ int FAST_FUNC getspnam_r(const char *name, struct spwd *struct_buf, char *buffer
|
|||||||
|
|
||||||
/****** getXXent_r */
|
/****** getXXent_r */
|
||||||
|
|
||||||
static int FAST_FUNC getXXent_r(void *struct_buf, char *buffer, size_t buflen,
|
static int FAST_FUNC getXXent_r(uintptr_t db_idx, char *buffer, size_t buflen,
|
||||||
void *result,
|
void *result)
|
||||||
unsigned db_idx)
|
|
||||||
{
|
{
|
||||||
char *buf;
|
char *buf;
|
||||||
struct passdb *db = &get_S()->db[db_idx];
|
struct passdb *db = &get_S()->db[db_idx];
|
||||||
|
|
||||||
*(void**)result = NULL;
|
|
||||||
|
|
||||||
if (!db->fp) {
|
if (!db->fp) {
|
||||||
db->fp = fopen_for_read(db->filename);
|
db->fp = fopen_for_read(db->filename);
|
||||||
if (!db->fp) {
|
if (!db->fp) {
|
||||||
@ -387,26 +392,14 @@ static int FAST_FUNC getXXent_r(void *struct_buf, char *buffer, size_t buflen,
|
|||||||
}
|
}
|
||||||
|
|
||||||
buf = parse_common(db->fp, db, /*no search key:*/ NULL, 0);
|
buf = parse_common(db->fp, db, /*no search key:*/ NULL, 0);
|
||||||
if (buf) {
|
return massage_data_for_r_func(db, buffer, buflen, result, buf);
|
||||||
size_t size = S.tokenize_end - buf;
|
|
||||||
if (size > buflen) {
|
|
||||||
errno = ERANGE;
|
|
||||||
} else {
|
|
||||||
memcpy(buffer, buf, size);
|
|
||||||
*(void**)result = convert_to_struct(db, buffer, struct_buf);
|
|
||||||
}
|
|
||||||
free(buf);
|
|
||||||
}
|
|
||||||
/* "The reentrant functions return zero on success.
|
|
||||||
* In case of error, an error number is returned."
|
|
||||||
* NB: not finding the record is also a "success" here:
|
|
||||||
*/
|
|
||||||
return errno;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int FAST_FUNC getpwent_r(struct passwd *struct_buf, char *buffer, size_t buflen, struct passwd **result)
|
int FAST_FUNC getpwent_r(struct passwd *struct_buf, char *buffer, size_t buflen,
|
||||||
|
struct passwd **result)
|
||||||
{
|
{
|
||||||
return getXXent_r(struct_buf, buffer, buflen, result, 0);
|
*result = struct_buf;
|
||||||
|
return getXXent_r(0, buffer, buflen, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
/****** getXXnam/id */
|
/****** getXXnam/id */
|
||||||
|
Loading…
Reference in New Issue
Block a user