From 40c1b22cd76995f0b614745c3954755e462b7f56 Mon Sep 17 00:00:00 2001 From: Ulrich Drepper Date: Wed, 15 Jun 2011 21:00:59 -0400 Subject: [PATCH] Cleanup of db-XXX.c --- ChangeLog | 2 + nss/nss_db/db-XXX.c | 122 +++++++++++++++++++++++++--------------------------- 2 files changed, 61 insertions(+), 63 deletions(-) diff --git a/ChangeLog b/ChangeLog index b580e29..33d9706 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,7 @@ 2011-06-15 Ulrich Drepper + * nss/nss_db/db-XXX.c: Cleanup. + * nss/Makefile (libnss_db-dbs): Add db-initgroups. * nss/Versions [libnss_db]: Add _nss_db_initgroups_dyn for GLIBC_PRIVATE. diff --git a/nss/nss_db/db-XXX.c b/nss/nss_db/db-XXX.c index 30026b1..3947893 100644 --- a/nss/nss_db/db-XXX.c +++ b/nss/nss_db/db-XXX.c @@ -122,8 +122,6 @@ enum nss_status \ _nss_db_get##name##_r (proto, struct STRUCTURE *result, \ char *buffer, size_t buflen, int *errnop H_ERRNO_PROTO)\ { \ - enum nss_status status = NSS_STATUS_SUCCESS; \ - struct nss_db_map state = { NULL, 0 }; \ struct parser_data *data = (void *) buffer; \ \ if (buflen < sizeof *data) \ @@ -133,7 +131,8 @@ enum nss_status \ return NSS_STATUS_TRYAGAIN; \ } \ \ - status = internal_setent (DBFILE, &state); \ + struct nss_db_map state = { NULL, 0 }; \ + enum nss_status status = internal_setent (DBFILE, &state); \ if (status != NSS_STATUS_SUCCESS) \ { \ *errnop = errno; \ @@ -141,77 +140,74 @@ enum nss_status \ return status; \ } \ \ - if (status == NSS_STATUS_SUCCESS) \ + const struct nss_db_header *header = state.header; \ + int i; \ + for (i = 0; i < header->ndbs; ++i) \ + if (header->dbs[i].id == db_char) \ + break; \ + if (i == header->ndbs) \ { \ - const struct nss_db_header *header = state.header; \ - int i; \ - for (i = 0; i < header->ndbs; ++i) \ - if (header->dbs[i].id == db_char) \ - break; \ - if (i == header->ndbs) \ - { \ - status = NSS_STATUS_UNAVAIL; \ - goto out; \ - } \ + status = NSS_STATUS_UNAVAIL; \ + goto out; \ + } \ \ - char *key; \ - if (db_char == '.') \ - key = (char *) IGNOREPATTERN keypattern; \ - else \ - { \ - const size_t size = (keysize) + 1; \ - key = alloca (size); \ + char *key; \ + if (db_char == '.') \ + key = (char *) IGNOREPATTERN keypattern; \ + else \ + { \ + const size_t size = (keysize) + 1; \ + key = alloca (size); \ \ - KEYPRINTF keypattern; \ - } \ + KEYPRINTF keypattern; \ + } \ \ - const stridx_t *hashtable \ - = (const stridx_t *) ((const char *) header \ - + header->dbs[i].hashoffset); \ - const char *valstrtab = (const char *) header + header->valstroffset; \ - uint32_t hashval = __hash_string (key); \ - size_t hidx = hashval % header->dbs[i].hashsize; \ - size_t hval2 = 1 + hashval % (header->dbs[i].hashsize - 2); \ + const stridx_t *hashtable \ + = (const stridx_t *) ((const char *) header \ + + header->dbs[i].hashoffset); \ + const char *valstrtab = (const char *) header + header->valstroffset; \ + uint32_t hashval = __hash_string (key); \ + size_t hidx = hashval % header->dbs[i].hashsize; \ + size_t hval2 = 1 + hashval % (header->dbs[i].hashsize - 2); \ \ - status = NSS_STATUS_NOTFOUND; \ - while (hashtable[hidx] != ~((stridx_t) 0)) \ + status = NSS_STATUS_NOTFOUND; \ + while (hashtable[hidx] != ~((stridx_t) 0)) \ + { \ + const char *valstr = valstrtab + hashtable[hidx]; \ + size_t len = strlen (valstr) + 1; \ + if (len > buflen) \ { \ - const char *valstr = valstrtab + hashtable[hidx]; \ - size_t len = strlen (valstr) + 1; \ - if (len > buflen) \ - { \ - /* No room to copy the data to. */ \ - *errnop = ERANGE; \ - H_ERRNO_SET (NETDB_INTERNAL); \ - status = NSS_STATUS_TRYAGAIN; \ - break; \ - } \ - \ - /* Copy the string to a place where it can be modified. */ \ - char *p = memcpy (buffer, valstr, len); \ + /* No room to copy the data to. */ \ + *errnop = ERANGE; \ + H_ERRNO_SET (NETDB_INTERNAL); \ + status = NSS_STATUS_TRYAGAIN; \ + break; \ + } \ \ - int err = parse_line (p, result, data, buflen, errnop \ - EXTRA_ARGS); \ - if (err > 0) \ - { \ - status = NSS_STATUS_SUCCESS; \ - break_if_match; \ - status = NSS_STATUS_NOTFOUND; \ - } \ - else if (err == -1) \ - { \ - H_ERRNO_SET (NETDB_INTERNAL); \ - status = NSS_STATUS_TRYAGAIN; \ - break; \ - } \ + /* Copy the string to a place where it can be modified. */ \ + char *p = memcpy (buffer, valstr, len); \ \ - if ((hidx += hval2) >= header->dbs[i].hashsize) \ - hidx -= header->dbs[i].hashsize; \ + int err = parse_line (p, result, data, buflen, errnop EXTRA_ARGS); \ + if (err > 0) \ + { \ + status = NSS_STATUS_SUCCESS; \ + break_if_match; \ + status = NSS_STATUS_NOTFOUND; \ + } \ + else if (err == -1) \ + { \ + H_ERRNO_SET (NETDB_INTERNAL); \ + status = NSS_STATUS_TRYAGAIN; \ + break; \ } \ \ - if (status == NSS_STATUS_NOTFOUND) \ - H_ERRNO_SET (HOST_NOT_FOUND); \ + if ((hidx += hval2) >= header->dbs[i].hashsize) \ + hidx -= header->dbs[i].hashsize; \ } \ + \ + if (status == NSS_STATUS_NOTFOUND) \ + H_ERRNO_SET (HOST_NOT_FOUND); \ + \ out: \ internal_endent (&state); \ \ -- 2.7.4