diff options
author | Ulrich Drepper <drepper@redhat.com> | 2003-04-28 08:17:29 +0000 |
---|---|---|
committer | Ulrich Drepper <drepper@redhat.com> | 2003-04-28 08:17:29 +0000 |
commit | 12c8051397a08cb582c5ccf39a49dae676a20074 (patch) | |
tree | a4e3da2a1ac06ac466059650ddbd718520cab96e | |
parent | fe453812315b3420771c0a1b5e5ea7d1d0626b93 (diff) | |
download | glibc-12c8051397a08cb582c5ccf39a49dae676a20074.zip glibc-12c8051397a08cb582c5ccf39a49dae676a20074.tar.gz glibc-12c8051397a08cb582c5ccf39a49dae676a20074.tar.bz2 |
Update.
2003-04-28 Ulrich Drepper <drepper@redhat.com>
* nscd/nscd_getgr_r.c: Compact code a bit. Add some __builtin_expect.
* nscd/nscd_getpw_r.c: Likewise.
* nscd/nscd_gethst_r.c: Likewise.
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | nscd/nscd_getgr_r.c | 50 | ||||
-rw-r--r-- | nscd/nscd_gethst_r.c | 43 | ||||
-rw-r--r-- | nscd/nscd_getpw_r.c | 35 |
4 files changed, 60 insertions, 74 deletions
@@ -1,3 +1,9 @@ +2003-04-28 Ulrich Drepper <drepper@redhat.com> + + * nscd/nscd_getgr_r.c: Compact code a bit. Add some __builtin_expect. + * nscd/nscd_getpw_r.c: Likewise. + * nscd/nscd_gethst_r.c: Likewise. + 2003-04-27 Ulrich Drepper <drepper@redhat.com> * nscd/pwdcache.c: Initialize .version element in result. diff --git a/nscd/nscd_getgr_r.c b/nscd/nscd_getgr_r.c index eae2544..9d9d7d5 100644 --- a/nscd/nscd_getgr_r.c +++ b/nscd/nscd_getgr_r.c @@ -70,6 +70,7 @@ nscd_getgr_r (const char *key, size_t keylen, request_type type, gr_response_header gr_resp; ssize_t nbytes; struct iovec vec[2]; + int result = -1; if (sock == -1) { @@ -88,25 +89,18 @@ nscd_getgr_r (const char *key, size_t keylen, request_type type, nbytes = TEMP_FAILURE_RETRY (__writev (sock, vec, 2)); if (nbytes != (ssize_t) (sizeof (request_header) + keylen)) - { - __close (sock); - return -1; - } + goto out; nbytes = TEMP_FAILURE_RETRY (__read (sock, &gr_resp, sizeof (gr_response_header))); if (nbytes != (ssize_t) sizeof (gr_response_header)) - { - __close (sock); - return -1; - } + goto out; if (gr_resp.found == -1) { /* The daemon does not cache this database. */ - __close (sock); __nss_not_use_nscd_group = 1; - return -1; + goto out; } if (gr_resp.found == 1) @@ -123,12 +117,12 @@ nscd_getgr_r (const char *key, size_t keylen, request_type type, & (__alignof__ (char *) - 1)); total_len = align + (1 + gr_resp.gr_mem_cnt) * sizeof (char *) + gr_resp.gr_name_len + gr_resp.gr_passwd_len; - if (buflen < total_len) + if (__builtin_expect (buflen < total_len, 0)) { no_room: __set_errno (ERANGE); - __close (sock); - return ERANGE; + result = ERANGE; + goto out; } buflen -= total_len; @@ -156,11 +150,9 @@ nscd_getgr_r (const char *key, size_t keylen, request_type type, total_len += gr_resp.gr_name_len + gr_resp.gr_passwd_len; /* Get this data. */ - if ((size_t) TEMP_FAILURE_RETRY (__readv (sock, vec, 2)) != total_len) - { - __close (sock); - return -1; - } + size_t n = TEMP_FAILURE_RETRY (__readv (sock, vec, 2)); + if (__builtin_expect (n != total_len, 0)) + goto out; /* Clear the terminating entry. */ resultbuf->gr_mem[gr_resp.gr_mem_cnt] = NULL; @@ -174,26 +166,28 @@ nscd_getgr_r (const char *key, size_t keylen, request_type type, p += len[cnt]; } - if (total_len > buflen) + if (__builtin_expect (total_len > buflen, 0)) goto no_room; - if ((size_t) TEMP_FAILURE_RETRY (__read (sock, resultbuf->gr_mem[0], - total_len)) != total_len) + result = 0; + n = TEMP_FAILURE_RETRY (__read (sock, resultbuf->gr_mem[0], + total_len)); + if (__builtin_expect (n != total_len, 0)) { - __close (sock); /* The `errno' to some value != ERANGE. */ __set_errno (ENOENT); - return ENOENT; + result = ENOENT; } - - __close (sock); - return 0; } else { - __close (sock); /* The `errno' to some value != ERANGE. */ __set_errno (ENOENT); - return ENOENT; + result = ENOENT; } + + out: + __close (sock); + + return result; } diff --git a/nscd/nscd_gethst_r.c b/nscd/nscd_gethst_r.c index 9488c53..69e7990 100644 --- a/nscd/nscd_gethst_r.c +++ b/nscd/nscd_gethst_r.c @@ -124,6 +124,7 @@ nscd_gethst_r (const char *key, size_t keylen, request_type type, request_header req; ssize_t nbytes; struct iovec vec[4]; + int result = -1; if (sock == -1) { @@ -142,25 +143,18 @@ nscd_gethst_r (const char *key, size_t keylen, request_type type, nbytes = TEMP_FAILURE_RETRY (__writev (sock, vec, 2)); if ((size_t) nbytes != sizeof (request_header) + req.key_len) - { - __close (sock); - return -1; - } + goto out; nbytes = TEMP_FAILURE_RETRY (__read (sock, &hst_resp, sizeof (hst_response_header))); - if (nbytes != sizeof (hst_response_header)) - { - __close (sock); - return -1; - } + if (__builtin_expect (nbytes != sizeof (hst_response_header), 0)) + goto out; if (hst_resp.found == -1) { /* The daemon does not cache this database. */ - __close (sock); __nss_not_use_nscd_hosts = 1; - return -1; + goto out; } if (hst_resp.found == 1) @@ -190,8 +184,8 @@ nscd_gethst_r (const char *key, size_t keylen, request_type type, { no_room: __set_errno (ERANGE); - __close (sock); - return ERANGE; + result = ERANGE; + goto out; } cp += align1; @@ -264,10 +258,7 @@ nscd_gethst_r (const char *key, size_t keylen, request_type type, resultbuf->h_addr_list[cnt] = NULL; if ((size_t) TEMP_FAILURE_RETRY (__readv (sock, vec, n)) != total_len) - { - __close (sock); - return -1; - } + goto out; /* Now we also can read the aliases. */ total_len = 0; @@ -285,23 +276,21 @@ nscd_gethst_r (const char *key, size_t keylen, request_type type, /* And finally read the aliases. */ if ((size_t) TEMP_FAILURE_RETRY (__read (sock, resultbuf->h_aliases[0], - total_len)) != total_len) - { - __close (sock); - return -1; - } - - __close (sock); - return 0; + total_len)) == total_len) + result = 0; } else { /* Store the error number. */ *h_errnop = hst_resp.error; - __close (sock); /* The `errno' to some value != ERANGE. */ __set_errno (ENOENT); - return ENOENT; + result = ENOENT; } + + out: + __close (sock); + + return result; } diff --git a/nscd/nscd_getpw_r.c b/nscd/nscd_getpw_r.c index abd059e..b0135d4 100644 --- a/nscd/nscd_getpw_r.c +++ b/nscd/nscd_getpw_r.c @@ -71,6 +71,7 @@ nscd_getpw_r (const char *key, size_t keylen, request_type type, pw_response_header pw_resp; ssize_t nbytes; struct iovec vec[2]; + int result = -1; if (sock == -1) { @@ -89,25 +90,18 @@ nscd_getpw_r (const char *key, size_t keylen, request_type type, nbytes = TEMP_FAILURE_RETRY (__writev (sock, vec, 2)); if (nbytes != (ssize_t) (sizeof (request_header) + keylen)) - { - __close (sock); - return -1; - } + goto out; nbytes = TEMP_FAILURE_RETRY (__read (sock, &pw_resp, sizeof (pw_response_header))); if (nbytes != (ssize_t) sizeof (pw_response_header)) - { - __close (sock); - return -1; - } + goto out; - if (pw_resp.found == -1) + if (__builtin_expect (pw_resp.found == -1, 0)) { /* The daemon does not cache this database. */ - __close (sock); __nss_not_use_nscd_passwd = 1; - return -1; + goto out; } if (pw_resp.found == 1) @@ -117,11 +111,11 @@ nscd_getpw_r (const char *key, size_t keylen, request_type type, + pw_resp.pw_gecos_len + pw_resp.pw_dir_len + pw_resp.pw_shell_len); - if (buflen < total) + if (__builtin_expect (buflen < total, 0)) { __set_errno (ERANGE); - __close (sock); - return ERANGE; + result = ERANGE; + goto out; } /* Set the information we already have. */ @@ -145,15 +139,18 @@ nscd_getpw_r (const char *key, size_t keylen, request_type type, nbytes = TEMP_FAILURE_RETRY (__read (sock, buffer, total)); - __close (sock); - - return nbytes == (ssize_t) total ? 0 : -1; + if (nbytes == (ssize_t) total) + result = 0; } else { - __close (sock); /* The `errno' to some value != ERANGE. */ __set_errno (ENOENT); - return ENOENT; + result = ENOENT; } + + out: + __close (sock); + + return result; } |