about summary refs log tree commit diff
path: root/nss/nss_db/db-XXX.c
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@gmail.com>2011-06-15 21:00:59 -0400
committerUlrich Drepper <drepper@gmail.com>2011-06-15 21:06:19 -0400
commit40c1b22cd76995f0b614745c3954755e462b7f56 (patch)
treee6efed7e6086773337ec02a2b28dcb12bc85f35a /nss/nss_db/db-XXX.c
parent9f2da732e7b03825027462dd1c46f8b4d18fc1f5 (diff)
downloadglibc-40c1b22cd76995f0b614745c3954755e462b7f56.tar.gz
glibc-40c1b22cd76995f0b614745c3954755e462b7f56.tar.xz
glibc-40c1b22cd76995f0b614745c3954755e462b7f56.zip
Cleanup of db-XXX.c
Diffstat (limited to 'nss/nss_db/db-XXX.c')
-rw-r--r--nss/nss_db/db-XXX.c122
1 files changed, 59 insertions, 63 deletions
diff --git a/nss/nss_db/db-XXX.c b/nss/nss_db/db-XXX.c
index 30026b1866..3947893284 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);						      \
 									      \