summary refs log tree commit diff
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2002-08-26 07:06:57 +0000
committerUlrich Drepper <drepper@redhat.com>2002-08-26 07:06:57 +0000
commit34816665b678a06e096a378303b68d35ff10a693 (patch)
tree471e49cf229dc64a80a72764e1d2db2c9c6e2818
parent40e15c4da81e899cbb4c6299fd4f48e1b1391115 (diff)
downloadglibc-34816665b678a06e096a378303b68d35ff10a693.tar.gz
glibc-34816665b678a06e096a378303b68d35ff10a693.tar.xz
glibc-34816665b678a06e096a378303b68d35ff10a693.zip
Update.
	* nss/getXXbyYY_r.c (REENTRANT_NAME): Return ENOENT if status is
	neither SUCCESS nor TRYAGAIN [PR libc/4259].
	* nss/nss_files/files-XXX.c (internal_getent): Don't set *errnop
	to ENOENT if no entry is found.
	* nis/nss_compat/compat-grp.c: Don't set errno in case of lookup
	failure.
	* nis/nss_compat/compat-initgroups.c: Likewise.
	* nis/nss_compat/compat-pwd.c: Likewise.
	* nis/nss_compat/compat-spwd.c: Likewise.
	* nis/nss_nis/nis-alias.c: Likewise.
	* nis/nss_nis/nis-ethers.c: Likewise.
	* nis/nss_nis/nis-grp.c: Likewise.
	* nis/nss_nis/nis-hosts.c: Likewise.
	* nis/nss_nis/nis-initgroups.c: Likewise.
	* nis/nss_nis/nis-netgrp.c: Likewise.
	* nis/nss_nis/nis-network.c: Likewise.
	* nis/nss_nis/nis-proto.c: Likewise.
	* nis/nss_nis/nis-publickey.c: Likewise.
	* nis/nss_nis/nis-pwd.c: Likewise.
	* nis/nss_nis/nis-rpc.c: Likewise.
	* nis/nss_nis/nis-service.c: Likewise.
	* nis/nss_nis/nis-spwd.c: Likewise.
	* resolv/nss_dns/dns-host.c: Likewise.
	* resolv/nss_dns/dns-network.c: Likewise.
	* nis/nss_nisplus/nisplus-alias.c: Save errno around NIS calls.
	* nis/nss_nisplus/nisplus-ethers.c: Likewise.
	* nis/nss_nisplus/nisplus-grp.c: Likewise.
	* nis/nss_nisplus/nisplus-hosts.c: Likewise.
	* nis/nss_nisplus/nisplus-network.c: Likewise.
	* nis/nss_nisplus/nisplus-proto.c: Likewise.
	* nis/nss_nisplus/nisplus-pwd.c: Likewise.
	* nis/nss_nisplus/nisplus-rpc.c: Likewise.
	* nis/nss_nisplus/nisplus-service.c: Likewise.
	* nis/nss_nisplus/nisplus-spwd.c: Likewise.
	* hesiod/nss_hesiod/hesiod-pwd.c (lookup): Preserve errno value.
	* hesiod/nss_hesiod/hesiod-proto.c (lookup): Likewise.
	* hesiod/nss_hesiod/hesiod-grp.c (lookup): Likewise.
	* hesiod/nss_hesiod/hesiod-service.c (lookup): Likewise.
-rw-r--r--ChangeLog39
-rw-r--r--hesiod/nss_hesiod/hesiod-grp.c12
-rw-r--r--hesiod/nss_hesiod/hesiod-proto.c15
-rw-r--r--hesiod/nss_hesiod/hesiod-pwd.c12
-rw-r--r--hesiod/nss_hesiod/hesiod-service.c15
-rw-r--r--linuxthreads/ChangeLog5
-rw-r--r--linuxthreads/Examples/ex10.c4
-rw-r--r--nis/nss_compat/compat-grp.c55
-rw-r--r--nis/nss_compat/compat-initgroups.c21
-rw-r--r--nis/nss_compat/compat-pwd.c89
-rw-r--r--nis/nss_compat/compat-spwd.c54
-rw-r--r--nis/nss_nis/nis-alias.c11
-rw-r--r--nis/nss_nis/nis-ethers.c22
-rw-r--r--nis/nss_nis/nis-grp.c20
-rw-r--r--nis/nss_nis/nis-hosts.c10
-rw-r--r--nis/nss_nis/nis-initgroups.c8
-rw-r--r--nis/nss_nis/nis-netgrp.c7
-rw-r--r--nis/nss_nis/nis-network.c25
-rw-r--r--nis/nss_nis/nis-proto.c26
-rw-r--r--nis/nss_nis/nis-publickey.c19
-rw-r--r--nis/nss_nis/nis-pwd.c24
-rw-r--r--nis/nss_nis/nis-rpc.c22
-rw-r--r--nis/nss_nis/nis-service.c28
-rw-r--r--nis/nss_nis/nis-spwd.c15
-rw-r--r--nis/nss_nisplus/nisplus-alias.c5
-rw-r--r--nis/nss_nisplus/nisplus-ethers.c5
-rw-r--r--nis/nss_nisplus/nisplus-grp.c13
-rw-r--r--nis/nss_nisplus/nisplus-hosts.c18
-rw-r--r--nis/nss_nisplus/nisplus-network.c18
-rw-r--r--nis/nss_nisplus/nisplus-proto.c18
-rw-r--r--nis/nss_nisplus/nisplus-pwd.c18
-rw-r--r--nis/nss_nisplus/nisplus-rpc.c15
-rw-r--r--nis/nss_nisplus/nisplus-service.c18
-rw-r--r--nis/nss_nisplus/nisplus-spwd.c10
-rw-r--r--nss/getXXbyYY_r.c3
-rw-r--r--nss/nss_files/files-XXX.c3
-rw-r--r--resolv/nss_dns/dns-host.c10
-rw-r--r--resolv/nss_dns/dns-network.c12
38 files changed, 337 insertions, 387 deletions
diff --git a/ChangeLog b/ChangeLog
index 2e8c1daecc..5cd6bf6645 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,44 @@
 2002-08-25  Ulrich Drepper  <drepper@redhat.com>
 
+	* nss/getXXbyYY_r.c (REENTRANT_NAME): Return ENOENT if status is
+	neither SUCCESS nor TRYAGAIN [PR libc/4259].
+	* nss/nss_files/files-XXX.c (internal_getent): Don't set *errnop
+	to ENOENT if no entry is found.
+	* nis/nss_compat/compat-grp.c: Don't set errno in case of lookup
+	failure.
+	* nis/nss_compat/compat-initgroups.c: Likewise.
+	* nis/nss_compat/compat-pwd.c: Likewise.
+	* nis/nss_compat/compat-spwd.c: Likewise.
+	* nis/nss_nis/nis-alias.c: Likewise.
+	* nis/nss_nis/nis-ethers.c: Likewise.
+	* nis/nss_nis/nis-grp.c: Likewise.
+	* nis/nss_nis/nis-hosts.c: Likewise.
+	* nis/nss_nis/nis-initgroups.c: Likewise.
+	* nis/nss_nis/nis-netgrp.c: Likewise.
+	* nis/nss_nis/nis-network.c: Likewise.
+	* nis/nss_nis/nis-proto.c: Likewise.
+	* nis/nss_nis/nis-publickey.c: Likewise.
+	* nis/nss_nis/nis-pwd.c: Likewise.
+	* nis/nss_nis/nis-rpc.c: Likewise.
+	* nis/nss_nis/nis-service.c: Likewise.
+	* nis/nss_nis/nis-spwd.c: Likewise.
+	* resolv/nss_dns/dns-host.c: Likewise.
+	* resolv/nss_dns/dns-network.c: Likewise.
+	* nis/nss_nisplus/nisplus-alias.c: Save errno around NIS calls.
+	* nis/nss_nisplus/nisplus-ethers.c: Likewise.
+	* nis/nss_nisplus/nisplus-grp.c: Likewise.
+	* nis/nss_nisplus/nisplus-hosts.c: Likewise.
+	* nis/nss_nisplus/nisplus-network.c: Likewise.
+	* nis/nss_nisplus/nisplus-proto.c: Likewise.
+	* nis/nss_nisplus/nisplus-pwd.c: Likewise.
+	* nis/nss_nisplus/nisplus-rpc.c: Likewise.
+	* nis/nss_nisplus/nisplus-service.c: Likewise.
+	* nis/nss_nisplus/nisplus-spwd.c: Likewise.
+	* hesiod/nss_hesiod/hesiod-pwd.c (lookup): Preserve errno value.
+	* hesiod/nss_hesiod/hesiod-proto.c (lookup): Likewise.
+	* hesiod/nss_hesiod/hesiod-grp.c (lookup): Likewise.
+	* hesiod/nss_hesiod/hesiod-service.c (lookup): Likewise.
+
 	* sysdeps/unix/sysv/linux/i386/sigaction.c: Avoid warnings by
 	declaring __restore and __restore_rt as hidden (if possible).
 
diff --git a/hesiod/nss_hesiod/hesiod-grp.c b/hesiod/nss_hesiod/hesiod-grp.c
index fdaf1f26f7..50c53f7893 100644
--- a/hesiod/nss_hesiod/hesiod-grp.c
+++ b/hesiod/nss_hesiod/hesiod-grp.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1997, 1999, 2000 Free Software Foundation, Inc.
+/* Copyright (C) 1997, 1999, 2000, 2002 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Mark Kettenis <kettenis@phys.uva.nl>, 1997.
 
@@ -57,6 +57,7 @@ lookup (const char *name, const char *type, struct group *grp,
   char **list;
   int parse_res;
   size_t len;
+  int olderr = errno;
 
   context = _nss_hesiod_init ();
   if (context == NULL)
@@ -65,8 +66,10 @@ lookup (const char *name, const char *type, struct group *grp,
   list = hesiod_resolve (context, name, type);
   if (list == NULL)
     {
+      int err = errno;
       hesiod_end (context);
-      return errno == ENOENT ? NSS_STATUS_NOTFOUND : NSS_STATUS_UNAVAIL;
+      __set_errno (olderr);
+      return err == ENOENT ? NSS_STATUS_NOTFOUND : NSS_STATUS_UNAVAIL;
     }
 
   linebuflen = buffer + buflen - data->linebuffer;
@@ -85,7 +88,10 @@ lookup (const char *name, const char *type, struct group *grp,
 
   parse_res = _nss_files_parse_grent (buffer, grp, data, buflen, errnop);
   if (parse_res < 1)
-    return parse_res == -1 ? NSS_STATUS_TRYAGAIN : NSS_STATUS_NOTFOUND;
+    {
+      __set_errno (olderr);
+      return parse_res == -1 ? NSS_STATUS_TRYAGAIN : NSS_STATUS_NOTFOUND;
+    }
 
   return NSS_STATUS_SUCCESS;
 }
diff --git a/hesiod/nss_hesiod/hesiod-proto.c b/hesiod/nss_hesiod/hesiod-proto.c
index 333f02a5f5..137b57202b 100644
--- a/hesiod/nss_hesiod/hesiod-proto.c
+++ b/hesiod/nss_hesiod/hesiod-proto.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1997, 2000 Free Software Foundation, Inc.
+/* Copyright (C) 1997, 2000, 2002 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Mark Kettenis <kettenis@phys.uva.nl>, 1997.
 
@@ -67,6 +67,7 @@ lookup (const char *name, const char *type, struct protoent *proto,
   char **list, **item;
   int parse_res;
   int found;
+  int olderr = errno;
 
   context = _nss_hesiod_init ();
   if (context == NULL)
@@ -75,8 +76,10 @@ lookup (const char *name, const char *type, struct protoent *proto,
   list = hesiod_resolve (context, name, type);
   if (list == NULL)
     {
+      int err = errno;
       hesiod_end (context);
-      return errno == ENOENT ? NSS_STATUS_NOTFOUND : NSS_STATUS_UNAVAIL;
+      __set_errno (olderr);
+      return err == ENOENT ? NSS_STATUS_NOTFOUND : NSS_STATUS_UNAVAIL;
     }
 
   linebuflen = buffer + buflen - data->linebuffer;
@@ -115,7 +118,13 @@ lookup (const char *name, const char *type, struct protoent *proto,
   hesiod_free_list (context, list);
   hesiod_end (context);
 
-  return found ? NSS_STATUS_SUCCESS : NSS_STATUS_NOTFOUND;
+  if (found == 0)
+    {
+      __set_errno (olderr);
+      return NSS_STATUS_NOTFOUND;
+    }
+
+  return NSS_STATUS_SUCCESS;
 }
 
 enum nss_status
diff --git a/hesiod/nss_hesiod/hesiod-pwd.c b/hesiod/nss_hesiod/hesiod-pwd.c
index 9f57e27906..2a7f65e2f0 100644
--- a/hesiod/nss_hesiod/hesiod-pwd.c
+++ b/hesiod/nss_hesiod/hesiod-pwd.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1997, 2000 Free Software Foundation, Inc.
+/* Copyright (C) 1997, 2000, 2002 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Mark Kettenis <kettenis@phys.uva.nl>, 1997.
 
@@ -55,6 +55,7 @@ lookup (const char *name, const char *type, struct passwd *pwd,
   char **list;
   int parse_res;
   size_t len;
+  int olderr = errno;
 
   context = _nss_hesiod_init ();
   if (context == NULL)
@@ -63,8 +64,10 @@ lookup (const char *name, const char *type, struct passwd *pwd,
   list = hesiod_resolve (context, name, type);
   if (list == NULL)
     {
+      int err = errno;
       hesiod_end (context);
-      return errno == ENOENT ? NSS_STATUS_NOTFOUND : NSS_STATUS_UNAVAIL;
+      __set_errno (olderr);
+      return err == ENOENT ? NSS_STATUS_NOTFOUND : NSS_STATUS_UNAVAIL;
     }
 
   linebuflen = buffer + buflen - data->linebuffer;
@@ -83,7 +86,10 @@ lookup (const char *name, const char *type, struct passwd *pwd,
 
   parse_res = _nss_files_parse_pwent (buffer, pwd, data, buflen, errnop);
   if (parse_res < 1)
-    return parse_res == -1 ? NSS_STATUS_TRYAGAIN : NSS_STATUS_NOTFOUND;
+    {
+      __set_errno (olderr);
+      return parse_res == -1 ? NSS_STATUS_TRYAGAIN : NSS_STATUS_NOTFOUND;
+    }
 
   return NSS_STATUS_SUCCESS;
 }
diff --git a/hesiod/nss_hesiod/hesiod-service.c b/hesiod/nss_hesiod/hesiod-service.c
index bd4cb612fb..cb5edd2859 100644
--- a/hesiod/nss_hesiod/hesiod-service.c
+++ b/hesiod/nss_hesiod/hesiod-service.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1997, 2000 Free Software Foundation, Inc.
+/* Copyright (C) 1997, 2000, 2002 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Mark Kettenis <kettenis@phys.uva.nl>, 1997.
 
@@ -68,6 +68,7 @@ lookup (const char *name, const char *type, const char *protocol,
   char **list, **item;
   int parse_res;
   int found;
+  int olderr = errno;
 
   context = _nss_hesiod_init ();
   if (context == NULL)
@@ -76,8 +77,10 @@ lookup (const char *name, const char *type, const char *protocol,
   list = hesiod_resolve (context, name, type);
   if (list == NULL)
     {
+      int err = errno;
       hesiod_end (context);
-      return errno == ENOENT ? NSS_STATUS_NOTFOUND : NSS_STATUS_UNAVAIL;
+      __set_errno (olderr);
+      return err == ENOENT ? NSS_STATUS_NOTFOUND : NSS_STATUS_UNAVAIL;
     }
 
   linebuflen = buffer + buflen - data->linebuffer;
@@ -116,7 +119,13 @@ lookup (const char *name, const char *type, const char *protocol,
   hesiod_free_list (context, list);
   hesiod_end (context);
 
-  return found ? NSS_STATUS_SUCCESS : NSS_STATUS_NOTFOUND;
+  if (found == 0)
+    {
+      __set_errno (olderr);
+      return NSS_STATUS_NOTFOUND;
+    }
+
+  return NSS_STATUS_SUCCESS;
 }
 
 enum nss_status
diff --git a/linuxthreads/ChangeLog b/linuxthreads/ChangeLog
index bc124a13c1..c689dc2164 100644
--- a/linuxthreads/ChangeLog
+++ b/linuxthreads/ChangeLog
@@ -1,3 +1,8 @@
+2002-08-26  Ulrich Drepper  <drepper@redhat.com>
+
+	* Examples/ex10.c (thread): tv_nsec == 1000000000 is already
+	overflow [PR libc/4244].
+
 2002-08-25  Ulrich Drepper  <drepper@redhat.com>
 
 	* sysdeps/pthread/timer_routines.c (thread_func): Make the
diff --git a/linuxthreads/Examples/ex10.c b/linuxthreads/Examples/ex10.c
index 8af1b6e1ca..9352f463a0 100644
--- a/linuxthreads/Examples/ex10.c
+++ b/linuxthreads/Examples/ex10.c
@@ -1,5 +1,5 @@
 /* Tests for pthread_mutex_timedlock function.
-   Copyright (C) 2000, 2001 Free Software Foundation, Inc.
+   Copyright (C) 2000, 2001, 2002 Free Software Foundation, Inc.
    Contributed by Kaz Kylheku <kaz@ashi.footprints.net>, 2000.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -67,7 +67,7 @@ thread (void *arg)
 
 	  ts.tv_nsec += TIMEOUT_NS;
 
-	  if (ts.tv_nsec > 1000000000L) {
+	  if (ts.tv_nsec >= 1000000000L) {
 	     ts.tv_sec++;
 	     ts.tv_nsec -= 1000000000L;
 	  }
diff --git a/nis/nss_compat/compat-grp.c b/nis/nss_compat/compat-grp.c
index cd939eb9e1..c9750ae1be 100644
--- a/nis/nss_compat/compat-grp.c
+++ b/nis/nss_compat/compat-grp.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1996, 1997, 1998, 1999, 2001 Free Software Foundation, Inc.
+/* Copyright (C) 1996,1997,1998,1999,2001,2002 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Thorsten Kukuk <kukuk@suse.de>, 1996.
 
@@ -246,7 +246,6 @@ getgrent_next_nis (struct group *result, ent_t *ent, char *buffer,
   if (yp_get_default_domain (&domain) != YPERR_SUCCESS)
     {
       ent->nis = 0;
-      *errnop = ENOENT;
       return NSS_STATUS_NOTFOUND;
     }
 
@@ -286,7 +285,6 @@ getgrent_next_nis (struct group *result, ent_t *ent, char *buffer,
 	      != YPERR_SUCCESS)
 	    {
 	      ent->nis = 0;
-	      *errnop = ENOENT;
 	      return NSS_STATUS_NOTFOUND;
 	    }
 
@@ -438,17 +436,11 @@ getgrnam_plusgroup (const char *name, struct group *result, char *buffer,
       int outvallen;
 
       if (yp_get_default_domain (&domain) != YPERR_SUCCESS)
-	{
-	  *errnop = ENOENT;
-	  return NSS_STATUS_NOTFOUND;
-	}
+	return NSS_STATUS_NOTFOUND;
 
       if (yp_match (domain, "group.byname", name, strlen (name),
 		    &outval, &outvallen) != YPERR_SUCCESS)
-	{
-	  *errnop = ENOENT;
-	  return NSS_STATUS_NOTFOUND;
-	}
+	return NSS_STATUS_NOTFOUND;
 
       if (buflen < ((size_t) outvallen + 1))
 	{
@@ -493,10 +485,8 @@ getgrent_next_file (struct group *result, ent_t *ent,
 	  buffer[buflen - 1] = '\xff';
 	  p = fgets (buffer, buflen, ent->stream);
 	  if (p == NULL && feof (ent->stream))
-	    {
-	      *errnop = ENOENT;
-	      return NSS_STATUS_NOTFOUND;
-	    }
+	    return NSS_STATUS_NOTFOUND;
+
 	  if (p == NULL || buffer[buflen - 1] != '\xff')
 	    {
 	      fsetpos (ent->stream, &pos);
@@ -636,10 +626,8 @@ internal_getgrnam_r (const char *name, struct group *result, ent_t *ent,
 	  buffer[buflen - 1] = '\xff';
 	  p = fgets (buffer, buflen, ent->stream);
 	  if (p == NULL && feof (ent->stream))
-	    {
-	      *errnop = ENOENT;
 	      return NSS_STATUS_NOTFOUND;
-	    }
+
 	  if (p == NULL || buffer[buflen - 1] != '\xff')
 	    {
 	      fsetpos (ent->stream, &pos);
@@ -681,10 +669,7 @@ internal_getgrnam_r (const char *name, struct group *result, ent_t *ent,
       if (result->gr_name[0] == '-' && result->gr_name[1] != '\0')
 	{
 	  if (strcmp (&result->gr_name[1], name) == 0)
-	    {
-	      *errnop = ENOENT;
-	      return NSS_STATUS_NOTFOUND;
-	    }
+	    return NSS_STATUS_NOTFOUND;
 	  else
 	    continue;
 	}
@@ -730,10 +715,7 @@ _nss_compat_getgrnam_r (const char *name, struct group *grp,
   enum nss_status status;
 
   if (name[0] == '-' || name[0] == '+')
-    {
-      *errnop = ENOENT;
-      return NSS_STATUS_NOTFOUND;
-    }
+    return NSS_STATUS_NOTFOUND;
 
   __libc_lock_lock (lock);
 
@@ -789,19 +771,13 @@ getgrgid_plusgroup (gid_t gid, struct group *result, char *buffer,
       int outvallen;
 
       if (yp_get_default_domain (&domain) != YPERR_SUCCESS)
-	{
-	  *errnop = ENOENT;
-	  return NSS_STATUS_NOTFOUND;
-	}
+	return NSS_STATUS_NOTFOUND;
 
       snprintf (buf, sizeof (buf), "%lu", (unsigned long int) gid);
 
       if (yp_match (domain, "group.bygid", buf, strlen (buf),
 		    &outval, &outvallen) != YPERR_SUCCESS)
-	{
-	  *errnop = ENOENT;
-	  return NSS_STATUS_NOTFOUND;
-	}
+	return NSS_STATUS_NOTFOUND;
 
       if (buflen < ((size_t) outvallen + 1))
 	{
@@ -848,10 +824,8 @@ internal_getgrgid_r (gid_t gid, struct group *result, ent_t *ent,
 	  buffer[buflen - 1] = '\xff';
 	  p = fgets (buffer, buflen, ent->stream);
 	  if (p == NULL && feof (ent->stream))
-	    {
-	      *errnop = ENOENT;
-	      return NSS_STATUS_NOTFOUND;
-	    }
+	    return NSS_STATUS_NOTFOUND;
+
 	  if (p == NULL || buffer[buflen - 1] != '\xff')
 	    {
 	      fsetpos (ent->stream, &pos);
@@ -918,10 +892,7 @@ internal_getgrgid_r (gid_t gid, struct group *result, ent_t *ent,
 
 	  status = getgrgid_plusgroup (gid, result, buffer, buflen, errnop);
 	  if (status == NSS_STATUS_RETURN) /* We couldn't parse the entry */
-	    {
-	      *errnop = ENOENT;
-	      return NSS_STATUS_NOTFOUND;
-	    }
+	    return NSS_STATUS_NOTFOUND;
 	  else
 	    return status;
 	}
diff --git a/nis/nss_compat/compat-initgroups.c b/nis/nss_compat/compat-initgroups.c
index 9f141fa3e3..824612286a 100644
--- a/nis/nss_compat/compat-initgroups.c
+++ b/nis/nss_compat/compat-initgroups.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
+/* Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Thorsten Kukuk <kukuk@suse.de>, 1998.
 
@@ -270,7 +270,6 @@ getgrent_next_nis (struct group *result, ent_t *ent, char *buffer,
   if (yp_get_default_domain (&domain) != YPERR_SUCCESS)
     {
       ent->nis = 0;
-      *errnop = ENOENT;
       return NSS_STATUS_NOTFOUND;
     }
 
@@ -287,7 +286,6 @@ getgrent_next_nis (struct group *result, ent_t *ent, char *buffer,
       if (ent->start == NULL || status != NSS_STATUS_SUCCESS)
 	{
 	  ent->nis = 0;
-	  *errnop = ENOENT;
 	  return NSS_STATUS_UNAVAIL;
 	}
     }
@@ -297,7 +295,6 @@ getgrent_next_nis (struct group *result, ent_t *ent, char *buffer,
     {
       if (ent->next == NULL)
         {
-          *errnop = ENOENT;
 	  ent->nis = 0;
           return NSS_STATUS_NOTFOUND;
         }
@@ -425,17 +422,11 @@ getgrnam_plusgroup (const char *name, struct group *result, char *buffer,
       int outvallen;
 
       if (yp_get_default_domain (&domain) != YPERR_SUCCESS)
-	{
-	  *errnop = ENOENT;
-	  return NSS_STATUS_NOTFOUND;
-	}
+	return NSS_STATUS_NOTFOUND;
 
       if (yp_match (domain, "group.byname", name, strlen (name),
 		    &outval, &outvallen) != YPERR_SUCCESS)
-	{
-	  *errnop = ENOENT;
-	  return NSS_STATUS_NOTFOUND;
-	}
+	return NSS_STATUS_NOTFOUND;
 
       if (buflen < ((size_t) outvallen + 1))
 	{
@@ -483,10 +474,8 @@ getgrent_next_file (struct group *result, ent_t *ent,
 	  buffer[buflen - 1] = '\xff';
 	  p = fgets (buffer, buflen, ent->stream);
 	  if (p == NULL && feof (ent->stream))
-	    {
-	      *errnop = ENOENT;
-	      return NSS_STATUS_NOTFOUND;
-	    }
+	    return NSS_STATUS_NOTFOUND;
+
 	  if (p == NULL || buffer[buflen - 1] != '\xff')
 	    {
 	      fsetpos (ent->stream, &pos);
diff --git a/nis/nss_compat/compat-pwd.c b/nis/nss_compat/compat-pwd.c
index 2a55df2908..5c9a551d88 100644
--- a/nis/nss_compat/compat-pwd.c
+++ b/nis/nss_compat/compat-pwd.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1996, 1997, 1998, 1999, 2001 Free Software Foundation, Inc.
+/* Copyright (C) 1996,1997,1998,1999,2001,2002 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1996.
 
@@ -223,7 +223,6 @@ insert_passwd_adjunct (char **result, int *len, char *domain, int *errnop)
       if ((res = malloc (namelen + restlen + (endp - encrypted) + 2)) == NULL)
 	{
 	  free (result2);
-	  *errnop = ENOMEM;
 	  return NSS_STATUS_TRYAGAIN;
 	}
 
@@ -753,7 +752,6 @@ getpwent_next_nis (struct passwd *result, ent_t *ent, char *buffer,
 	    {
 	      ent->nis = 0;
 	      give_pwd_free (&ent->pwd);
-	      *errnop = ENOENT;
 	      return NSS_STATUS_NOTFOUND;
 	    }
 
@@ -862,10 +860,7 @@ getpwnam_plususer (const char *name, struct passwd *result, ent_t *ent,
 	}
 
       if (in_blacklist (result->pw_name, strlen (result->pw_name), ent))
-	{
-	  *errnop = ENOENT;
-	  return NSS_STATUS_NOTFOUND;
-	}
+	return NSS_STATUS_NOTFOUND;
     }
   else /* Use NIS */
     {
@@ -873,17 +868,11 @@ getpwnam_plususer (const char *name, struct passwd *result, ent_t *ent,
       int outvallen;
 
       if (yp_get_default_domain (&domain) != YPERR_SUCCESS)
-	{
-	  *errnop = ENOENT;
-	  return NSS_STATUS_NOTFOUND;
-	}
+	return NSS_STATUS_NOTFOUND;
 
       if (yp_match (domain, "passwd.byname", name, strlen (name),
 		    &outval, &outvallen) != YPERR_SUCCESS)
-	{
-	  *errnop = ENOENT;
-	  return NSS_STATUS_NOTFOUND;
-	}
+	return NSS_STATUS_NOTFOUND;
 
       if (insert_passwd_adjunct (&outval, &outvallen, domain, errnop)
 	  != NSS_STATUS_SUCCESS)
@@ -910,10 +899,7 @@ getpwnam_plususer (const char *name, struct passwd *result, ent_t *ent,
 	return NSS_STATUS_TRYAGAIN;
 
       if (in_blacklist (result->pw_name, strlen (result->pw_name), ent))
-	{
-	  *errnop = ENOENT;
-	  return NSS_STATUS_NOTFOUND;
-	}
+	return NSS_STATUS_NOTFOUND;
     }
 
   if (parse_res > 0)
@@ -949,10 +935,8 @@ getpwent_next_file (struct passwd *result, ent_t *ent,
 	  buffer[buflen - 1] = '\xff';
 	  p = fgets (buffer, buflen, ent->stream);
 	  if (p == NULL && feof (ent->stream))
-	    {
-	      *errnop = ENOENT;
-	      return NSS_STATUS_NOTFOUND;
-	    }
+	    return NSS_STATUS_NOTFOUND;
+
 	  if (p == NULL || buffer[buflen - 1] != '\xff')
 	    {
 	      fsetpos (ent->stream, &pos);
@@ -1027,11 +1011,7 @@ getpwent_next_file (struct passwd *result, ent_t *ent,
 	  if (status == NSS_STATUS_RETURN)
 	    continue;
 	  else
-	    {
-	      if (status == NSS_STATUS_NOTFOUND)
-		*errnop = ENOENT;
-	      return status;
-	    }
+	    return status;
 	}
 
       /* -user */
@@ -1171,7 +1151,6 @@ internal_getpwnam_r (const char *name, struct passwd *result, ent_t *ent,
 	  p = fgets (buffer, buflen, ent->stream);
 	  if (p == NULL && feof (ent->stream))
 	    {
-	      *errnop = ENOENT;
 	      return NSS_STATUS_NOTFOUND;
 	    }
 	  if (p == NULL || buffer[buflen - 1] != '\xff')
@@ -1244,10 +1223,7 @@ internal_getpwnam_r (const char *name, struct passwd *result, ent_t *ent,
 	  && result->pw_name[1] != '@')
 	{
 	  if (strcmp (&result->pw_name[1], name) == 0)
-	    {
-	      *errnop = ENOENT;
-	      return NSS_STATUS_NOTFOUND;
-	    }
+	    return NSS_STATUS_NOTFOUND;
 	  else
 	    continue;
 	}
@@ -1298,10 +1274,7 @@ _nss_compat_getpwnam_r (const char *name, struct passwd *pwd,
   enum nss_status status;
 
   if (name[0] == '-' || name[0] == '+')
-    {
-      *errnop = ENOENT;
-      return NSS_STATUS_NOTFOUND;
-    }
+    return NSS_STATUS_NOTFOUND;
 
   __libc_lock_lock (lock);
 
@@ -1379,19 +1352,13 @@ getpwuid_plususer (uid_t uid, struct passwd *result, char *buffer,
       int outvallen;
 
       if (yp_get_default_domain (&domain) != YPERR_SUCCESS)
-        {
-          *errnop = ENOENT;
-          return NSS_STATUS_NOTFOUND;
-        }
+	return NSS_STATUS_NOTFOUND;
 
       sprintf (buf, "%lu", (unsigned long int) uid);
       if (yp_match (domain, "passwd.byuid", buf, strlen (buf),
                     &outval, &outvallen)
           != YPERR_SUCCESS)
-        {
-          *errnop = ENOENT;
-          return NSS_STATUS_NOTFOUND;
-        }
+	return NSS_STATUS_NOTFOUND;
 
       if (insert_passwd_adjunct (&outval, &outvallen, domain, errnop)
           != NSS_STATUS_SUCCESS)
@@ -1452,10 +1419,8 @@ internal_getpwuid_r (uid_t uid, struct passwd *result, ent_t *ent,
           buffer[buflen - 1] = '\xff';
           p = fgets (buffer, buflen, ent->stream);
           if (p == NULL && feof (ent->stream))
-	    {
-	      *errnop = ENOENT;
-	      return NSS_STATUS_NOTFOUND;
-	    }
+	    return NSS_STATUS_NOTFOUND;
+
           if (p == NULL || buffer[buflen - 1] != '\xff')
             {
               fsetpos (ent->stream, &pos);
@@ -1505,10 +1470,8 @@ internal_getpwuid_r (uid_t uid, struct passwd *result, ent_t *ent,
 	  status = getpwuid_plususer (uid, result, buffer, buflen, errnop);
 	  if (status == NSS_STATUS_SUCCESS &&
 	      innetgr (buf, NULL, result->pw_name, NULL))
-	    {
-	      *errnop = ENOENT;
-	      return NSS_STATUS_NOTFOUND;
-	    }
+	    return NSS_STATUS_NOTFOUND;
+
           continue;
         }
 
@@ -1533,10 +1496,7 @@ internal_getpwuid_r (uid_t uid, struct passwd *result, ent_t *ent,
 	    }
 	  else
             if (status == NSS_STATUS_RETURN) /* We couldn't parse the entry */
-	      {
-		*errnop = ENOENT;
-		return NSS_STATUS_NOTFOUND;
-	      }
+	      return NSS_STATUS_NOTFOUND;
             else
               return status;
 
@@ -1555,10 +1515,7 @@ internal_getpwuid_r (uid_t uid, struct passwd *result, ent_t *ent,
 	  status = getpwuid_plususer (uid, result, buffer, buflen, errnop);
 	  if (status == NSS_STATUS_SUCCESS &&
 	      innetgr (buf, NULL, result->pw_name, NULL))
-	    {
-	      *errnop = ENOENT;
-	      return NSS_STATUS_NOTFOUND;
-	    }
+	    return NSS_STATUS_NOTFOUND;
           continue;
         }
 
@@ -1583,10 +1540,7 @@ internal_getpwuid_r (uid_t uid, struct passwd *result, ent_t *ent,
 	    }
 	  else
             if (status == NSS_STATUS_RETURN) /* We couldn't parse the entry */
-	      {
-		*errnop = ENOENT;
-		return NSS_STATUS_NOTFOUND;
-	      }
+	      return NSS_STATUS_NOTFOUND;
             else
               return status;
 
@@ -1603,10 +1557,7 @@ internal_getpwuid_r (uid_t uid, struct passwd *result, ent_t *ent,
             break;
           else
             if (status == NSS_STATUS_RETURN) /* We couldn't parse the entry */
-	      {
-		*errnop = ENOENT;
-		return NSS_STATUS_NOTFOUND;
-	      }
+	      return NSS_STATUS_NOTFOUND;
             else
               return status;
         }
diff --git a/nis/nss_compat/compat-spwd.c b/nis/nss_compat/compat-spwd.c
index bb9dd85bf9..8ce02e3da3 100644
--- a/nis/nss_compat/compat-spwd.c
+++ b/nis/nss_compat/compat-spwd.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1996, 1997, 1998, 1999, 2001 Free Software Foundation, Inc.
+/* Copyright (C) 1996,1997,1998,1999,2001,2002 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1996.
 
@@ -636,7 +636,6 @@ getspent_next_nis (struct spwd *result, ent_t *ent,
 	    {
 	      ent->nis = 0;
 	      give_spwd_free (&ent->pwd);
-	      *errnop = ENOENT;
 	      return NSS_STATUS_NOTFOUND;
 	    }
 
@@ -746,16 +745,12 @@ getspnam_plususer (const char *name, struct spwd *result, char *buffer,
       int outvallen;
 
       if (yp_get_default_domain (&domain) != YPERR_SUCCESS)
-	{
-	  *errnop = ENOENT;
-	  return NSS_STATUS_NOTFOUND;
-	}
+	return NSS_STATUS_NOTFOUND;
+
       if (yp_match (domain, "shadow.byname", name, strlen (name),
 		    &outval, &outvallen)  != YPERR_SUCCESS)
-	{
-	  *errnop = ENOENT;
-	  return NSS_STATUS_NOTFOUND;
-	}
+	return NSS_STATUS_NOTFOUND;
+
       if (buflen < ((size_t) outvallen + 1))
 	{
 	  free (outval);
@@ -805,10 +800,8 @@ getspent_next_file (struct spwd *result, ent_t *ent,
 	  buffer[buflen - 1] = '\xff';
 	  p = fgets (buffer, buflen, ent->stream);
 	  if (p == NULL && feof (ent->stream))
-	    {
-	      *errnop = ENOENT;
-	      return NSS_STATUS_NOTFOUND;
-	    }
+	    return NSS_STATUS_NOTFOUND;
+
 	  if (p == NULL || buffer[buflen - 1] != '\xff')
 	    {
 	      fsetpos (ent->stream, &pos);
@@ -1016,10 +1009,8 @@ internal_getspnam_r (const char *name, struct spwd *result, ent_t *ent,
 	  buffer[buflen - 1] = '\xff';
 	  p = fgets (buffer, buflen, ent->stream);
 	  if (p == NULL && feof (ent->stream))
-	    {
-	      *errnop = ENOENT;
-	      return NSS_STATUS_NOTFOUND;
-	    }
+	    return NSS_STATUS_NOTFOUND;
+
 	  if (p == NULL || buffer[buflen - 1] != '\xff')
 	    {
 	      fsetpos (ent->stream, &pos);
@@ -1070,10 +1061,7 @@ internal_getspnam_r (const char *name, struct spwd *result, ent_t *ent,
 	    {
 	      if (user != NULL && user[0] != '-')
 		if (strcmp (user, name) == 0)
-		  {
-		    *errnop = ENOENT;
-		    return NSS_STATUS_NOTFOUND;
-		  }
+		  return NSS_STATUS_NOTFOUND;
 	    }
 	  __internal_endnetgrent (&netgrdata);
 	  continue;
@@ -1113,10 +1101,7 @@ internal_getspnam_r (const char *name, struct spwd *result, ent_t *ent,
 	  && result->sp_namp[1] != '@')
 	{
 	  if (strcmp (&result->sp_namp[1], name) == 0)
-	    {
-	      *errnop = ENOENT;
-	      return NSS_STATUS_NOTFOUND;
-	    }
+	    return NSS_STATUS_NOTFOUND;
 	  else
 	    continue;
 	}
@@ -1132,11 +1117,8 @@ internal_getspnam_r (const char *name, struct spwd *result, ent_t *ent,
 	      status = getspnam_plususer (name, result, buffer, buflen,
 					  errnop);
 	      if (status == NSS_STATUS_RETURN)
-		{
-		  /* We couldn't parse the entry */
-		  *errnop = ENOENT;
-		  return NSS_STATUS_NOTFOUND;
-		}
+		/* We couldn't parse the entry */
+		return NSS_STATUS_NOTFOUND;
 	      else
 		return status;
 	    }
@@ -1149,10 +1131,7 @@ internal_getspnam_r (const char *name, struct spwd *result, ent_t *ent,
 
 	  status = getspnam_plususer (name, result, buffer, buflen, errnop);
 	  if (status == NSS_STATUS_RETURN) /* We couldn't parse the entry */
-	    {
-	      *errnop = ENOENT;
-	      return NSS_STATUS_NOTFOUND;
-	    }
+	    return NSS_STATUS_NOTFOUND;
 	  else
 	    return status;
 	}
@@ -1169,10 +1148,7 @@ _nss_compat_getspnam_r (const char *name, struct spwd *pwd,
   enum nss_status status;
 
   if (name[0] == '-' || name[0] == '+')
-    {
-      *errnop = ENOENT;
-      return NSS_STATUS_NOTFOUND;
-    }
+    return NSS_STATUS_NOTFOUND;
 
   if (ni == NULL)
     {
diff --git a/nis/nss_nis/nis-alias.c b/nis/nss_nis/nis-alias.c
index 8b78126b21..2ceaa1da64 100644
--- a/nis/nss_nis/nis-alias.c
+++ b/nis/nss_nis/nis-alias.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1996, 1997, 1998, 1999i, 2001 Free Software Foundation, Inc.
+/* Copyright (C) 1996,1997,1998,1999,2001,2002 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1996.
 
@@ -167,9 +167,7 @@ internal_nis_getaliasent_r (struct aliasent *alias, char *buffer,
 				      &result, &len));
       if (retval != NSS_STATUS_SUCCESS)
 	{
-	  if (retval == NSS_STATUS_NOTFOUND)
-	    *errnop = ENOENT;
-	  else if (retval == NSS_STATUS_TRYAGAIN)
+	  if (retval == NSS_STATUS_TRYAGAIN)
             *errnop = errno;
           return retval;
         }
@@ -278,10 +276,7 @@ _nss_nis_getaliasbyname_r (const char *name, struct aliasent *alias,
       if (parse_res == -1)
 	return NSS_STATUS_TRYAGAIN;
       else
-	{
-	  *errnop = ENOENT;
-	  return NSS_STATUS_NOTFOUND;
-	}
+	return NSS_STATUS_NOTFOUND;
     }
 
   return NSS_STATUS_SUCCESS;
diff --git a/nis/nss_nis/nis-ethers.c b/nis/nss_nis/nis-ethers.c
index 8c446209ad..54f10a5d0d 100644
--- a/nis/nss_nis/nis-ethers.c
+++ b/nis/nss_nis/nis-ethers.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1996-2000, 2001 Free Software Foundation, Inc.
+/* Copyright (C) 1996-2000, 2001, 2002 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Thorsten Kukuk <kukuk@suse.de>, 1996.
 
@@ -159,10 +159,8 @@ internal_nis_getetherent_r (struct etherent *eth, char *buffer, size_t buflen,
       char *p;
 
       if (next == NULL)
-	{
-	  *errnop = ENOENT;
-	  return NSS_STATUS_NOTFOUND;
-	}
+	return NSS_STATUS_NOTFOUND;
+
       p = strncpy (buffer, next->val, buflen);
 
       while (isspace (*p))
@@ -216,9 +214,7 @@ _nss_nis_gethostton_r (const char *name, struct etherent *eth,
 
   if (retval != NSS_STATUS_SUCCESS)
     {
-      if (retval == NSS_STATUS_NOTFOUND)
-	*errnop = ENOENT;
-      else if (retval == NSS_STATUS_TRYAGAIN)
+      if (retval == NSS_STATUS_TRYAGAIN)
         *errnop = errno;
       return retval;
     }
@@ -242,10 +238,7 @@ _nss_nis_gethostton_r (const char *name, struct etherent *eth,
       if (parse_res == -1)
 	return NSS_STATUS_TRYAGAIN;
       else
-	{
-	  *errnop = ENOENT;
-	  return NSS_STATUS_NOTFOUND;
-	}
+	return NSS_STATUS_NOTFOUND;
     }
   return NSS_STATUS_SUCCESS;
 }
@@ -306,10 +299,7 @@ _nss_nis_getntohost_r (const struct ether_addr *addr, struct etherent *eth,
       if (parse_res == -1)
 	return NSS_STATUS_TRYAGAIN;
       else
-	{
-	  *errnop = ENOENT;
-	  return NSS_STATUS_NOTFOUND;
-	}
+	return NSS_STATUS_NOTFOUND;
     }
   return NSS_STATUS_SUCCESS;
 }
diff --git a/nis/nss_nis/nis-grp.c b/nis/nss_nis/nis-grp.c
index e85d68bdf7..68db76636b 100644
--- a/nis/nss_nis/nis-grp.c
+++ b/nis/nss_nis/nis-grp.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1996, 1997, 1998, 1999, 2001 Free Software Foundation, Inc.
+/* Copyright (C) 1996,1997,1998,1999,2001,2002 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Thorsten Kukuk <kukuk@suse.de>, 1996.
 
@@ -104,9 +104,7 @@ internal_nis_getgrent_r (struct group *grp, char *buffer, size_t buflen,
 
       if (retval != NSS_STATUS_SUCCESS)
         {
-	  if (retval == NSS_STATUS_NOTFOUND)
-	    *errnop = ENOENT;
-          else if (retval == NSS_STATUS_TRYAGAIN)
+          if (retval == NSS_STATUS_TRYAGAIN)
             *errnop = errno;
           return retval;
         }
@@ -206,10 +204,7 @@ _nss_nis_getgrnam_r (const char *name, struct group *grp,
       if (parse_res == -1)
 	return NSS_STATUS_TRYAGAIN;
       else
-	{
-	  *errnop = ENOENT;
-	  return NSS_STATUS_NOTFOUND;
-	}
+	return NSS_STATUS_NOTFOUND;
     }
   return NSS_STATUS_SUCCESS;
 }
@@ -234,9 +229,7 @@ _nss_nis_getgrgid_r (gid_t gid, struct group *grp,
 
   if (retval != NSS_STATUS_SUCCESS)
     {
-      if (retval == NSS_STATUS_NOTFOUND)
-	*errnop = ENOENT;
-      else if (retval == NSS_STATUS_TRYAGAIN)
+      if (retval == NSS_STATUS_TRYAGAIN)
         *errnop = errno;
       return retval;
     }
@@ -260,10 +253,7 @@ _nss_nis_getgrgid_r (gid_t gid, struct group *grp,
       if (parse_res == -1)
 	return NSS_STATUS_TRYAGAIN;
       else
-	{
-	  *errnop = ENOENT;
-	  return NSS_STATUS_NOTFOUND;
-	}
+	return NSS_STATUS_NOTFOUND;
     }
   return NSS_STATUS_SUCCESS;
 }
diff --git a/nis/nss_nis/nis-hosts.c b/nis/nss_nis/nis-hosts.c
index c855a0a7a3..9b0332939c 100644
--- a/nis/nss_nis/nis-hosts.c
+++ b/nis/nss_nis/nis-hosts.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1996, 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
+/* Copyright (C) 1996,1997,1998,1999,2000,2002 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Thorsten Kukuk <kukuk@suse.de>, 1996.
 
@@ -181,7 +181,6 @@ internal_nis_gethostent_r (struct hostent *host, char *buffer,
 	      *h_errnop = TRY_AGAIN;
 	      break;
 	    case NSS_STATUS_NOTFOUND:
-	      *errnop = ENOENT;
 	      *h_errnop = HOST_NOT_FOUND;
 	      break;
 	    default:
@@ -321,7 +320,6 @@ internal_gethostbyname2_r (const char *name, int af, struct hostent *host,
       else
 	{
 	  *h_errnop = HOST_NOT_FOUND;
-	  *errnop = ENOENT;
 	  return NSS_STATUS_NOTFOUND;
 	}
     }
@@ -393,10 +391,8 @@ _nss_nis_gethostbyaddr_r (const void *addr, socklen_t addrlen, int af,
 	  *errnop = errno;
 	}
       if (retval == NSS_STATUS_NOTFOUND)
-	{
-	  *h_errnop = HOST_NOT_FOUND;
-	  *errnop = ENOENT;
-	}
+	*h_errnop = HOST_NOT_FOUND;
+
       return retval;
     }
 
diff --git a/nis/nss_nis/nis-initgroups.c b/nis/nss_nis/nis-initgroups.c
index bdeb3ad088..de7444e870 100644
--- a/nis/nss_nis/nis-initgroups.c
+++ b/nis/nss_nis/nis-initgroups.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1998, 1999, 2000 Free Software Foundation, Inc.
+/* Copyright (C) 1998, 1999, 2000, 2002 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Thorsten Kukuk <kukuk@suse.de>, 1998.
 
@@ -119,10 +119,8 @@ internal_getgrent_r (struct group *grp, char *buffer, size_t buflen,
   do
     {
       if (intern->next == NULL)
-	{
-	  *errnop = ENOENT;
-	  return NSS_STATUS_NOTFOUND;
-	}
+	return NSS_STATUS_NOTFOUND;
+
       p = strncpy (buffer, intern->next->val, buflen);
       while (isspace (*p))
         ++p;
diff --git a/nis/nss_nis/nis-netgrp.c b/nis/nss_nis/nis-netgrp.c
index f5a73e79bb..c9b52428c3 100644
--- a/nis/nss_nis/nis-netgrp.c
+++ b/nis/nss_nis/nis-netgrp.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1996, 1997, 1999, 2000 Free Software Foundation, Inc.
+/* Copyright (C) 1996, 1997, 1999, 2000, 2002 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Thorsten Kukuk <kukuk@suse.de>, 1996.
 
@@ -116,10 +116,7 @@ _nss_nis_getnetgrent_r (struct __netgrent *result, char *buffer, size_t buflen,
   enum nss_status status;
 
   if (cursor == NULL)
-    {
-      *errnop = ENOENT;
-      return NSS_STATUS_NOTFOUND;
-    }
+    return NSS_STATUS_NOTFOUND;
 
   __libc_lock_lock (lock);
 
diff --git a/nis/nss_nis/nis-network.c b/nis/nss_nis/nis-network.c
index 25215a7674..0e40b6f26c 100644
--- a/nis/nss_nis/nis-network.c
+++ b/nis/nss_nis/nis-network.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1996-2000, 2001 Free Software Foundation, Inc.
+/* Copyright (C) 1996-2000, 2001, 2002 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1996.
 
@@ -105,9 +105,7 @@ internal_nis_getnetent_r (struct netent *net, char *buffer, size_t buflen,
 
       if (retval != NSS_STATUS_SUCCESS)
         {
-	  if (retval == NSS_STATUS_NOTFOUND)
-	    *errnop = ENOENT;
-          else if (retval == NSS_STATUS_TRYAGAIN)
+          if (retval == NSS_STATUS_TRYAGAIN)
 	    {
 	      *herrnop = NETDB_INTERNAL;
 	      *errnop = errno;
@@ -206,9 +204,7 @@ _nss_nis_getnetbyname_r (const char *name, struct netent *net, char *buffer,
 
   if (retval != NSS_STATUS_SUCCESS)
     {
-      if (retval == NSS_STATUS_NOTFOUND)
-	*errnop = ENOENT;
-      else if (retval == NSS_STATUS_TRYAGAIN)
+      if (retval == NSS_STATUS_TRYAGAIN)
 	{
 	  *errnop = errno;
 	  *herrnop = NETDB_INTERNAL;
@@ -238,10 +234,7 @@ _nss_nis_getnetbyname_r (const char *name, struct netent *net, char *buffer,
       if (parse_res == -1)
 	return NSS_STATUS_TRYAGAIN;
       else
-	{
-	  *errnop = ENOENT;
-	  return NSS_STATUS_NOTFOUND;
-	}
+	return NSS_STATUS_NOTFOUND;
     }
   else
     return NSS_STATUS_SUCCESS;
@@ -289,10 +282,7 @@ _nss_nis_getnetbyaddr_r (uint32_t addr, int type, struct netent *net,
 		    continue;
 		  }
 		else
-		  {
-		    *errnop = ENOENT;
-		    return NSS_STATUS_NOTFOUND;
-		  }
+		  return NSS_STATUS_NOTFOUND;
 	      }
 	    else
 	      {
@@ -324,10 +314,7 @@ _nss_nis_getnetbyaddr_r (uint32_t addr, int type, struct netent *net,
 	    if (parse_res == -1)
 	      return NSS_STATUS_TRYAGAIN;
 	    else
-	      {
-		*errnop = ENOENT;
-		return NSS_STATUS_NOTFOUND;
-	      }
+	      return NSS_STATUS_NOTFOUND;
 	  }
 	else
 	  return NSS_STATUS_SUCCESS;
diff --git a/nis/nss_nis/nis-proto.c b/nis/nss_nis/nis-proto.c
index 867c8da159..00e86dfa6b 100644
--- a/nis/nss_nis/nis-proto.c
+++ b/nis/nss_nis/nis-proto.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1996, 1997, 1998, 2000, 2001 Free Software Foundation, Inc.
+/* Copyright (C) 1996,1997,1998,2000,2001,2002 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Thorsten Kukuk <kukuk@suse.de>, 1996.
 
@@ -156,10 +156,8 @@ internal_nis_getprotoent_r (struct protoent *proto,
       char *p;
 
       if (next == NULL)
-	{
-	  *errnop = ENOENT;
-	  return NSS_STATUS_NOTFOUND;
-	}
+	return NSS_STATUS_NOTFOUND;
+
       p = strncpy (buffer, next->val, buflen);
 
       while (isspace (*p))
@@ -213,9 +211,7 @@ _nss_nis_getprotobyname_r (const char *name, struct protoent *proto,
 
   if (retval != NSS_STATUS_SUCCESS)
     {
-      if (retval == NSS_STATUS_NOTFOUND)
-	*errnop = ENOENT;
-      else if (retval == NSS_STATUS_TRYAGAIN)
+      if (retval == NSS_STATUS_TRYAGAIN)
 	*errnop = errno;
       return retval;
     }
@@ -239,10 +235,7 @@ _nss_nis_getprotobyname_r (const char *name, struct protoent *proto,
       if (parse_res == -1)
 	return NSS_STATUS_TRYAGAIN;
       else
-	{
-	  *errnop = ENOENT;
-	  return NSS_STATUS_NOTFOUND;
-	}
+	return NSS_STATUS_NOTFOUND;
     }
   return NSS_STATUS_SUCCESS;
 }
@@ -267,9 +260,7 @@ _nss_nis_getprotobynumber_r (int number, struct protoent *proto,
 
   if (retval != NSS_STATUS_SUCCESS)
     {
-      if (retval == NSS_STATUS_NOTFOUND)
-	*errnop = ENOENT;
-      else if (retval == NSS_STATUS_TRYAGAIN)
+      if (retval == NSS_STATUS_TRYAGAIN)
 	*errnop = errno;
       return retval;
     }
@@ -293,10 +284,7 @@ _nss_nis_getprotobynumber_r (int number, struct protoent *proto,
       if (parse_res == -1)
 	return NSS_STATUS_TRYAGAIN;
       else
-	{
-	  *errnop = ENOENT;
-	  return NSS_STATUS_NOTFOUND;
-	}
+	return NSS_STATUS_NOTFOUND;
     }
   return NSS_STATUS_SUCCESS;
 }
diff --git a/nis/nss_nis/nis-publickey.c b/nis/nss_nis/nis-publickey.c
index f686054426..6e92112d11 100644
--- a/nis/nss_nis/nis-publickey.c
+++ b/nis/nss_nis/nis-publickey.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1996, 1997, 1998, 1999, 2001 Free Software Foundation, Inc.
+/* Copyright (C) 1996,1997,1998,1999,2001,2002 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Thorsten Kukuk <kukuk@suse.de>, 1996.
 
@@ -61,9 +61,7 @@ _nss_nis_getpublickey (const char *netname, char *pkey, int *errnop)
 
   if (retval != NSS_STATUS_SUCCESS)
     {
-      if (retval == NSS_STATUS_NOTFOUND)
-	*errnop = ENOENT;
-      else if (retval == NSS_STATUS_TRYAGAIN)
+      if (retval == NSS_STATUS_TRYAGAIN)
 	*errnop = errno;
       return retval;
     }
@@ -109,9 +107,7 @@ _nss_nis_getsecretkey (const char *netname, char *skey, char *passwd,
 
   if (retval != NSS_STATUS_SUCCESS)
     {
-      if (retval == NSS_STATUS_NOTFOUND)
-	*errnop = ENOENT;
-      else if (retval == NSS_STATUS_TRYAGAIN)
+      if (retval == NSS_STATUS_TRYAGAIN)
 	*errnop = errno;
       return retval;
     }
@@ -180,7 +176,7 @@ parse_netid_str (const char *s, uid_t *uidp, gid_t *gidp, int *gidlenp,
   gidlen = 0;
 
   /* After strtoul() ep should point to the first invalid character.
-     This is the marker "," we search for the next value.  */ 
+     This is the marker "," we search for the next value.  */
   while (ep != NULL && *ep == ',')
     {
       ep++;
@@ -221,7 +217,6 @@ _nss_nis_netname2user (char netname[MAXNETNAMELEN + 1], uid_t *uidp,
       break;			/* the successful case */
     case YPERR_DOMAIN:
     case YPERR_KEY:
-      *errnop = ENOENT;
       return NSS_STATUS_NOTFOUND;
     case YPERR_MAP:
     default:
@@ -238,9 +233,7 @@ _nss_nis_netname2user (char netname[MAXNETNAMELEN + 1], uid_t *uidp,
       return err;
     }
   else
-    {
-      *errnop = ENOENT;
-      return NSS_STATUS_NOTFOUND;
-    }
+    return NSS_STATUS_NOTFOUND;
+
   return NSS_STATUS_SUCCESS;
 }
diff --git a/nis/nss_nis/nis-pwd.c b/nis/nss_nis/nis-pwd.c
index 4845fd1c75..da5ffabff1 100644
--- a/nis/nss_nis/nis-pwd.c
+++ b/nis/nss_nis/nis-pwd.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1996, 1997, 1998, 2001 Free Software Foundation, Inc.
+/* Copyright (C) 1996, 1997, 1998, 2001, 2002 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1996.
 
@@ -106,9 +106,7 @@ internal_nis_getpwent_r (struct passwd *pwd, char *buffer, size_t buflen,
 
       if (retval != NSS_STATUS_SUCCESS)
         {
-	  if (retval == NSS_STATUS_NOTFOUND)
-	    *errnop = ENOENT;
-          else if (retval == NSS_STATUS_TRYAGAIN)
+          if (retval == NSS_STATUS_TRYAGAIN)
             *errnop = errno;
           return retval;
         }
@@ -233,9 +231,7 @@ _nss_nis_getpwnam_r (const char *name, struct passwd *pwd,
 
   if (retval != NSS_STATUS_SUCCESS)
     {
-      if (retval == NSS_STATUS_NOTFOUND)
-	*errnop = ENOENT;
-      else if (retval == NSS_STATUS_TRYAGAIN)
+      if (retval == NSS_STATUS_TRYAGAIN)
 	*errnop = errno;
       return retval;
     }
@@ -306,10 +302,7 @@ _nss_nis_getpwnam_r (const char *name, struct passwd *pwd,
       if (parse_res == -1)
         return NSS_STATUS_TRYAGAIN;
       else
-	{
-	  *errnop = ENOENT;
-	  return NSS_STATUS_NOTFOUND;
-	}
+	return NSS_STATUS_NOTFOUND;
     }
   else
     return NSS_STATUS_SUCCESS;
@@ -336,9 +329,7 @@ _nss_nis_getpwuid_r (uid_t uid, struct passwd *pwd,
 
   if (retval != NSS_STATUS_SUCCESS)
     {
-      if (retval == NSS_STATUS_NOTFOUND)
-	*errnop = ENOENT;
-      else if (retval == NSS_STATUS_TRYAGAIN)
+      if (retval == NSS_STATUS_TRYAGAIN)
 	*errnop = errno;
       return retval;
     }
@@ -410,10 +401,7 @@ _nss_nis_getpwuid_r (uid_t uid, struct passwd *pwd,
       if (parse_res == -1)
         return NSS_STATUS_TRYAGAIN;
      else
-       {
-	 *errnop = ENOENT;
-	 return NSS_STATUS_NOTFOUND;
-       }
+       return NSS_STATUS_NOTFOUND;
     }
   else
     return NSS_STATUS_SUCCESS;
diff --git a/nis/nss_nis/nis-rpc.c b/nis/nss_nis/nis-rpc.c
index 8c1a3d4860..1f9e5b4600 100644
--- a/nis/nss_nis/nis-rpc.c
+++ b/nis/nss_nis/nis-rpc.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1996, 1997, 1998, 2000 Free Software Foundation, Inc.
+/* Copyright (C) 1996, 1997, 1998, 2000, 2002 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Thorsten Kukuk <kukuk@suse.de>, 1996.
 
@@ -173,10 +173,8 @@ internal_nis_getrpcent_r (struct rpcent *rpc, char *buffer, size_t buflen,
   do
     {
       if (data->next == NULL)
-	{
-	  *errnop = ENOENT;
-	  return NSS_STATUS_NOTFOUND;
-	}
+	return NSS_STATUS_NOTFOUND;
+
       p = strncpy (buffer, data->next->val, buflen);
       while (isspace (*p))
         ++p;
@@ -251,10 +249,7 @@ _nss_nis_getrpcbyname_r (const char *name, struct rpcent *rpc,
   internal_nis_endrpcent (&data);
 
   if (!found && status == NSS_STATUS_SUCCESS)
-    {
-      *errnop = ENOENT;
-      return NSS_STATUS_NOTFOUND;
-    }
+    return NSS_STATUS_NOTFOUND;
   else
     return status;
 }
@@ -279,9 +274,7 @@ _nss_nis_getrpcbynumber_r (int number, struct rpcent *rpc,
 
   if (retval != NSS_STATUS_SUCCESS)
     {
-      if (retval == NSS_STATUS_NOTFOUND)
-	*errnop = ENOENT;
-      else if (retval == NSS_STATUS_TRYAGAIN)
+      if (retval == NSS_STATUS_TRYAGAIN)
 	*errnop = errno;
       return retval;
     }
@@ -306,10 +299,7 @@ _nss_nis_getrpcbynumber_r (int number, struct rpcent *rpc,
       if (parse_res == -1)
 	return NSS_STATUS_TRYAGAIN;
       else
-	{
-	  *errnop = ENOENT;
-	  return NSS_STATUS_NOTFOUND;
-	}
+	return NSS_STATUS_NOTFOUND;
     }
   else
     return NSS_STATUS_SUCCESS;
diff --git a/nis/nss_nis/nis-service.c b/nis/nss_nis/nis-service.c
index bd2227afc3..6affdb5209 100644
--- a/nis/nss_nis/nis-service.c
+++ b/nis/nss_nis/nis-service.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1996,1997,1998,1999,2000,2001 Free Software Foundation, Inc.
+/* Copyright (C) 1996-2001, 2002 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Thorsten Kukuk <kukuk@suse.de>, 1996.
 
@@ -173,10 +173,8 @@ internal_nis_getservent_r (struct servent *serv, char *buffer,
   do
     {
       if (data->next == NULL)
-	{
-	  *errnop = ENOENT;
-	  return NSS_STATUS_NOTFOUND;
-	}
+	return NSS_STATUS_NOTFOUND;
+
       p = strncpy (buffer, data->next->val, buflen);
       while (isspace (*p))
         ++p;
@@ -270,10 +268,7 @@ _nss_nis_getservbyname_r (const char *name, const char *protocol,
 	      if (parse_res == -1)
 		return NSS_STATUS_TRYAGAIN;
 	      else
-		{
-		  *errnop = ENOENT;
-		  return NSS_STATUS_NOTFOUND;
-		}
+		return NSS_STATUS_NOTFOUND;
 	    }
 	  else
 	    return NSS_STATUS_SUCCESS;
@@ -305,10 +300,7 @@ _nss_nis_getservbyname_r (const char *name, const char *protocol,
   internal_nis_endservent (&data);
 
   if (!found && status == NSS_STATUS_SUCCESS)
-    {
-      *errnop = ENOENT;
-      return NSS_STATUS_NOTFOUND;
-    }
+    return NSS_STATUS_NOTFOUND;
   else
     return status;
 }
@@ -367,10 +359,7 @@ _nss_nis_getservbyport_r (int port, const char *protocol,
 	      if (parse_res == -1)
 		return NSS_STATUS_TRYAGAIN;
 	      else
-		{
-		  *errnop = ENOENT;
-		  return NSS_STATUS_NOTFOUND;
-		}
+		return NSS_STATUS_NOTFOUND;
 	    }
 	  else
 	    return NSS_STATUS_SUCCESS;
@@ -392,10 +381,7 @@ _nss_nis_getservbyport_r (int port, const char *protocol,
   internal_nis_endservent (&data);
 
   if (!found && status == NSS_STATUS_SUCCESS)
-    {
-      *errnop = ENOENT;
-      return NSS_STATUS_NOTFOUND;
-    }
+    return NSS_STATUS_NOTFOUND;
   else
     return status;
 }
diff --git a/nis/nss_nis/nis-spwd.c b/nis/nss_nis/nis-spwd.c
index 907ba395bf..c06e95457e 100644
--- a/nis/nss_nis/nis-spwd.c
+++ b/nis/nss_nis/nis-spwd.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1996, 1997, 1998, 2001 Free Software Foundation, Inc.
+/* Copyright (C) 1996, 1997, 1998, 2001, 2002 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1996.
 
@@ -104,9 +104,7 @@ internal_nis_getspent_r (struct spwd *sp, char *buffer, size_t buflen,
 
       if (retval != NSS_STATUS_SUCCESS)
         {
-          if (retval == NSS_STATUS_NOTFOUND)
-	    *errnop = ENOENT;
-	  else if (retval == NSS_STATUS_TRYAGAIN)
+	  if (retval == NSS_STATUS_TRYAGAIN)
 	    *errnop = errno;
           return retval;
         }
@@ -180,9 +178,7 @@ _nss_nis_getspnam_r (const char *name, struct spwd *sp,
 
   if (retval != NSS_STATUS_SUCCESS)
     {
-      if (retval == NSS_STATUS_NOTFOUND)
-	*errnop = ENOENT;
-      else if (retval == NSS_STATUS_TRYAGAIN)
+      if (retval == NSS_STATUS_TRYAGAIN)
 	*errnop = errno;
       return retval;
     }
@@ -206,10 +202,7 @@ _nss_nis_getspnam_r (const char *name, struct spwd *sp,
       if (parse_res == -1)
 	return NSS_STATUS_TRYAGAIN;
       else
-	{
-	  *errnop = ENOENT;
-	  return NSS_STATUS_NOTFOUND;
-	}
+	return NSS_STATUS_NOTFOUND;
     }
   return NSS_STATUS_SUCCESS;
 }
diff --git a/nis/nss_nisplus/nisplus-alias.c b/nis/nss_nisplus/nisplus-alias.c
index 3b6888eae7..e05c5edda3 100644
--- a/nis/nss_nisplus/nisplus-alias.c
+++ b/nis/nss_nisplus/nisplus-alias.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1997, 1998, 2001 Free Software Foundation, Inc.
+/* Copyright (C) 1997, 1998, 2001, 2002 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1997.
 
@@ -274,6 +274,7 @@ _nss_nisplus_getaliasbyname_r (const char *name, struct aliasent *alias,
     {
       nis_result *result;
       char buf[strlen (name) + 30 + tablename_len];
+      int olderr = errno;
 
       sprintf (buf, "[name=%s],%s", name, tablename_val);
 
@@ -286,6 +287,8 @@ _nss_nisplus_getaliasbyname_r (const char *name, struct aliasent *alias,
 					       buffer, buflen, errnop);
       if (parse_res < 1)
 	{
+	  __set_errno (olderr);
+
 	  if (parse_res == -1)
 	    return NSS_STATUS_TRYAGAIN;
 	  else
diff --git a/nis/nss_nisplus/nisplus-ethers.c b/nis/nss_nisplus/nisplus-ethers.c
index 94b433abd2..2fd152dfdb 100644
--- a/nis/nss_nisplus/nisplus-ethers.c
+++ b/nis/nss_nisplus/nisplus-ethers.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1997, 1998, 2000, 2001 Free Software Foundation, Inc.
+/* Copyright (C) 1997, 1998, 2000, 2001, 2002 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Thorsten Kukuk <kukuk@suse.de>, 1997.
 
@@ -231,6 +231,7 @@ _nss_nisplus_gethostton_r (const char *name, struct etherent *eth,
     {
       nis_result *result;
       char buf[strlen (name) + 40 + tablename_len];
+      int olderr = errno;
 
       sprintf (buf, "[name=%s],%s", name, tablename_val);
 
@@ -247,6 +248,8 @@ _nss_nisplus_gethostton_r (const char *name, struct etherent *eth,
 					       buflen, errnop);
       if (parse_res < 1)
 	{
+	  __set_errno (olderr);
+
 	  if (parse_res == -1)
 	    {
 	      nis_freeresult (result);
diff --git a/nis/nss_nisplus/nisplus-grp.c b/nis/nss_nisplus/nisplus-grp.c
index 84bc6746a5..f66c14f8ed 100644
--- a/nis/nss_nisplus/nisplus-grp.c
+++ b/nis/nss_nisplus/nisplus-grp.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1997, 2001 Free Software Foundation, Inc.
+/* Copyright (C) 1997, 2001, 2002 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1997.
 
@@ -180,6 +180,7 @@ _nss_nisplus_getgrnam_r (const char *name, struct group *gr,
     {
       nis_result *result;
       char buf[strlen (name) + 24 + tablename_len];
+      int olderr = errno;
 
       sprintf (buf, "[name=%s],%s", name, tablename_val);
 
@@ -204,7 +205,10 @@ _nss_nisplus_getgrnam_r (const char *name, struct group *gr,
 	      return NSS_STATUS_TRYAGAIN;
 	    }
 	  else
-	    return NSS_STATUS_NOTFOUND;
+	    {
+	      __set_errno (olderr);
+	      return NSS_STATUS_NOTFOUND;
+	    }
 	}
       return NSS_STATUS_SUCCESS;
     }
@@ -226,6 +230,7 @@ _nss_nisplus_getgrgid_r (const gid_t gid, struct group *gr,
     int parse_res;
     nis_result *result;
     char buf[36 + tablename_len];
+    int olderr = errno;
 
     sprintf (buf, "[gid=%lu],%s", (unsigned long int) gid, tablename_val);
 
@@ -235,6 +240,8 @@ _nss_nisplus_getgrgid_r (const gid_t gid, struct group *gr,
       {
 	enum nss_status status = niserr2nss (result->status);
 
+	__set_errno (olderr);
+
 	nis_freeresult (result);
 	return status;
       }
@@ -245,6 +252,8 @@ _nss_nisplus_getgrgid_r (const gid_t gid, struct group *gr,
     nis_freeresult (result);
     if (parse_res < 1)
       {
+	__set_errno (olderr);
+
 	if (parse_res == -1)
 	  {
 	    *errnop = ERANGE;
diff --git a/nis/nss_nisplus/nisplus-hosts.c b/nis/nss_nisplus/nisplus-hosts.c
index 6fc208a202..b8c9fdf228 100644
--- a/nis/nss_nisplus/nisplus-hosts.c
+++ b/nis/nss_nisplus/nisplus-hosts.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1997, 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
+/* Copyright (C) 1997,1998,1999,2000,2001,2002 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Thorsten Kukuk <kukuk@suse.de>, 1997.
 
@@ -354,6 +354,7 @@ internal_gethostbyname2_r (const char *name, int af, struct hostent *host,
     {
       nis_result *result;
       char buf[strlen (name) + 255 + tablename_len];
+      int olderr = errno;
 
       /* Search at first in the alias list, and use the correct name
 	 for the next search */
@@ -383,6 +384,8 @@ internal_gethostbyname2_r (const char *name, int af, struct hostent *host,
 	      *errnop = errno;
               *herrnop = NETDB_INTERNAL;
             }
+	  else
+	    __set_errno (olderr);
 	  nis_freeresult (result);
           return retval;
         }
@@ -402,7 +405,10 @@ internal_gethostbyname2_r (const char *name, int af, struct hostent *host,
 	  return NSS_STATUS_TRYAGAIN;
 	}
       else
-	return NSS_STATUS_NOTFOUND;
+	{
+	  __set_errno (olderr);
+	  return NSS_STATUS_NOTFOUND;
+	}
     }
 }
 
@@ -467,6 +473,7 @@ _nss_nisplus_gethostbyaddr_r (const void *addr, socklen_t addrlen, int af,
       nis_result *result;
       char buf[255 + tablename_len];
       int retval, parse_res;
+      int olderr = errno;
 
       sprintf (buf, "[addr=%s],%s",
 	       inet_ntoa (*(const struct in_addr *) addr), tablename_val);
@@ -480,6 +487,8 @@ _nss_nisplus_gethostbyaddr_r (const void *addr, socklen_t addrlen, int af,
 	      *errnop = errno;
               *herrnop = NETDB_INTERNAL;
             }
+	  else
+	    __set_errno (olderr);
 	  nis_freeresult (result);
           return retval;
         }
@@ -499,6 +508,9 @@ _nss_nisplus_gethostbyaddr_r (const void *addr, socklen_t addrlen, int af,
 	  return NSS_STATUS_TRYAGAIN;
 	}
       else
-	return NSS_STATUS_NOTFOUND;
+	{
+	  __set_errno (olderr);
+	  return NSS_STATUS_NOTFOUND;
+	}
     }
 }
diff --git a/nis/nss_nisplus/nisplus-network.c b/nis/nss_nisplus/nisplus-network.c
index 201c154769..d99bf76ca4 100644
--- a/nis/nss_nisplus/nisplus-network.c
+++ b/nis/nss_nisplus/nisplus-network.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1997, 1998, 2000, 2001 Free Software Foundation, Inc.
+/* Copyright (C) 1997, 1998, 2000, 2001, 2002 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1997.
 
@@ -312,6 +312,7 @@ _nss_nisplus_getnetbyname_r (const char *name, struct netent *network,
     {
       nis_result *result;
       char buf[strlen (name) + 255 + tablename_len];
+      int olderr = errno;
 
       /* Search at first in the alias list, and use the correct name
 	 for the next search */
@@ -341,6 +342,8 @@ _nss_nisplus_getnetbyname_r (const char *name, struct netent *network,
 	      *errnop = errno;
 	      *herrnop = NETDB_INTERNAL;
 	    }
+	  else
+	    __set_errno (olderr);
 	  nis_freeresult (result);
 	  return retval;
 	}
@@ -360,7 +363,10 @@ _nss_nisplus_getnetbyname_r (const char *name, struct netent *network,
 	  return NSS_STATUS_TRYAGAIN;
 	}
       else
-	return NSS_STATUS_NOTFOUND;
+	{
+	  __set_errno (olderr);
+	  return NSS_STATUS_NOTFOUND;
+	}
     }
 }
 
@@ -385,6 +391,7 @@ _nss_nisplus_getnetbyaddr_r (uint32_t addr, const int type,
     struct in_addr in;
     char buf2[256];
     int b2len;
+    int olderr = errno;
 
     in = inet_makeaddr (addr, 0);
     strcpy (buf2, inet_ntoa (in));
@@ -414,6 +421,8 @@ _nss_nisplus_getnetbyaddr_r (uint32_t addr, const int type,
 		*errnop = errno;
 		*herrnop = NETDB_INTERNAL;
 	      }
+	    else
+	      __set_errno (olderr);
 	    nis_freeresult (result);
 	    return retval;
 	  }
@@ -433,7 +442,10 @@ _nss_nisplus_getnetbyaddr_r (uint32_t addr, const int type,
 	    return NSS_STATUS_TRYAGAIN;
 	  }
 	else
-	  return NSS_STATUS_NOTFOUND;
+	  {
+	    __set_errno (olderr);
+	    return NSS_STATUS_NOTFOUND;
+	  }
       }
   }
 }
diff --git a/nis/nss_nisplus/nisplus-proto.c b/nis/nss_nisplus/nisplus-proto.c
index 6613f53d3d..10f9a38e67 100644
--- a/nis/nss_nisplus/nisplus-proto.c
+++ b/nis/nss_nisplus/nisplus-proto.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1997, 1998, 2001 Free Software Foundation, Inc.
+/* Copyright (C) 1997, 1998, 2001, 2002 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1997.
 
@@ -289,6 +289,7 @@ _nss_nisplus_getprotobyname_r (const char *name, struct protoent *proto,
     {
       nis_result *result;
       char buf[strlen (name) + 255 + tablename_len];
+      int olderr = errno;
 
       /* Search at first in the alias list, and use the correct name
          for the next search */
@@ -314,6 +315,8 @@ _nss_nisplus_getprotobyname_r (const char *name, struct protoent *proto,
 	{
 	  enum nss_status status = niserr2nss (result->status);
 
+	  __set_errno (olderr);
+
 	  nis_freeresult (result);
 	  return status;
 	}
@@ -331,7 +334,10 @@ _nss_nisplus_getprotobyname_r (const char *name, struct protoent *proto,
 	      return NSS_STATUS_TRYAGAIN;
 	    }
 	  else
-	    return NSS_STATUS_NOTFOUND;
+	    {
+	      __set_errno (olderr);
+	      return NSS_STATUS_NOTFOUND;
+	    }
 	}
       return NSS_STATUS_SUCCESS;
     }
@@ -353,6 +359,7 @@ _nss_nisplus_getprotobynumber_r (const int number, struct protoent *proto,
     int parse_res;
     nis_result *result;
     char buf[46 + tablename_len];
+    int olderr = errno;
 
     sprintf (buf, "[number=%d],%s", number, tablename_val);
 
@@ -362,6 +369,8 @@ _nss_nisplus_getprotobynumber_r (const int number, struct protoent *proto,
       {
 	enum nss_status status = niserr2nss (result->status);
 
+	__set_errno (olderr);
+
 	nis_freeresult (result);
 	return status;
       }
@@ -379,7 +388,10 @@ _nss_nisplus_getprotobynumber_r (const int number, struct protoent *proto,
 	    return NSS_STATUS_TRYAGAIN;
 	  }
 	else
-	  return NSS_STATUS_NOTFOUND;
+	  {
+	    __set_errno (olderr);
+	    return NSS_STATUS_NOTFOUND;
+	  }
       }
     return NSS_STATUS_SUCCESS;
   }
diff --git a/nis/nss_nisplus/nisplus-pwd.c b/nis/nss_nisplus/nisplus-pwd.c
index f7bc8321bd..a4beb7af14 100644
--- a/nis/nss_nisplus/nisplus-pwd.c
+++ b/nis/nss_nisplus/nisplus-pwd.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1997, 1999, 2001 Free Software Foundation, Inc.
+/* Copyright (C) 1997, 1999, 2001, 2002 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1997.
 
@@ -186,6 +186,7 @@ _nss_nisplus_getpwnam_r (const char *name, struct passwd *pw,
     {
       nis_result *result;
       char buf[strlen (name) + 24 + tablename_len];
+      int olderr = errno;
 
       sprintf (buf, "[name=%s],%s", name, tablename_val);
 
@@ -195,6 +196,8 @@ _nss_nisplus_getpwnam_r (const char *name, struct passwd *pw,
 	{
 	  enum nss_status status =  niserr2nss (result->status);
 
+	  __set_errno (olderr);
+
 	  nis_freeresult (result);
 	  return status;
 	}
@@ -212,7 +215,10 @@ _nss_nisplus_getpwnam_r (const char *name, struct passwd *pw,
 	      return NSS_STATUS_TRYAGAIN;
 	    }
 	  else
-	    return NSS_STATUS_NOTFOUND;
+	    {
+	      __set_errno (olderr);
+	      return NSS_STATUS_NOTFOUND;
+	    }
 	}
       return NSS_STATUS_SUCCESS;
     }
@@ -234,6 +240,7 @@ _nss_nisplus_getpwuid_r (const uid_t uid, struct passwd *pw,
     int parse_res;
     nis_result *result;
     char buf[100 + tablename_len];
+    int olderr = errno;
 
     sprintf (buf, "[uid=%lu],%s", (unsigned long int) uid, tablename_val);
 
@@ -243,6 +250,8 @@ _nss_nisplus_getpwuid_r (const uid_t uid, struct passwd *pw,
       {
 	enum nss_status status = niserr2nss (result->status);
 
+	__set_errno (olderr);
+
 	nis_freeresult (result);
 	return status;
       }
@@ -259,7 +268,10 @@ _nss_nisplus_getpwuid_r (const uid_t uid, struct passwd *pw,
 	    return NSS_STATUS_TRYAGAIN;
 	  }
 	else
-	  return NSS_STATUS_NOTFOUND;
+	  {
+	    __set_errno (olderr);
+	    return NSS_STATUS_NOTFOUND;
+	  }
       }
     return NSS_STATUS_SUCCESS;
   }
diff --git a/nis/nss_nisplus/nisplus-rpc.c b/nis/nss_nisplus/nisplus-rpc.c
index e35d846ed3..8e661baedb 100644
--- a/nis/nss_nisplus/nisplus-rpc.c
+++ b/nis/nss_nisplus/nisplus-rpc.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1997, 1998, 2001 Free Software Foundation, Inc.
+/* Copyright (C) 1997, 1998, 2001, 2002 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1997.
 
@@ -283,6 +283,7 @@ _nss_nisplus_getrpcbyname_r (const char *name, struct rpcent *rpc,
     {
       nis_result *result;
       char buf[strlen (name) + 255 + tablename_len];
+      int olderr = errno;
 
       /* Search at first in the alias list, and use the correct name
          for the next search */
@@ -308,6 +309,8 @@ _nss_nisplus_getrpcbyname_r (const char *name, struct rpcent *rpc,
 	{
 	  enum nss_status status = niserr2nss (result->status);
 
+	  __set_errno (olderr);
+
 	  nis_freeresult (result);
 	  return status;
 	}
@@ -324,6 +327,8 @@ _nss_nisplus_getrpcbyname_r (const char *name, struct rpcent *rpc,
 	      *errnop = ERANGE;
 	      return NSS_STATUS_TRYAGAIN;
 	    }
+
+	  __set_errno (olderr);
 	  return NSS_STATUS_NOTFOUND;
 	}
       return NSS_STATUS_SUCCESS;
@@ -346,6 +351,7 @@ _nss_nisplus_getrpcbynumber_r (const int number, struct rpcent *rpc,
     int parse_res;
     nis_result *result;
     char buf[100 + tablename_len];
+    int olderr = errno;
 
     sprintf (buf, "[number=%d],%s", number, tablename_val);
 
@@ -355,6 +361,8 @@ _nss_nisplus_getrpcbynumber_r (const int number, struct rpcent *rpc,
       {
 	enum nss_status status = niserr2nss (result->status);
 
+	__set_errno (olderr);
+
 	nis_freeresult (result);
 	return status;
       }
@@ -372,7 +380,10 @@ _nss_nisplus_getrpcbynumber_r (const int number, struct rpcent *rpc,
 	    return NSS_STATUS_TRYAGAIN;
 	  }
 	else
-	  return NSS_STATUS_NOTFOUND;
+	  {
+	    __set_errno (olderr);
+	    return NSS_STATUS_NOTFOUND;
+	  }
       }
     return NSS_STATUS_SUCCESS;
   }
diff --git a/nis/nss_nisplus/nisplus-service.c b/nis/nss_nisplus/nisplus-service.c
index 5560da5ea0..a010f44da8 100644
--- a/nis/nss_nisplus/nisplus-service.c
+++ b/nis/nss_nisplus/nisplus-service.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1997, 1998, 1999, 2001 Free Software Foundation, Inc.
+/* Copyright (C) 1997, 1998, 1999, 2001, 2002 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Thorsten Kukuk <kukuk@suse.de>, 1997.
 
@@ -297,6 +297,7 @@ _nss_nisplus_getservbyname_r (const char *name, const char *protocol,
     {
       nis_result *result;
       char buf[strlen (name) + 255 + tablename_len];
+      int olderr = errno;
 
       /* Search at first in the alias list, and use the correct name
          for the next search */
@@ -324,6 +325,8 @@ _nss_nisplus_getservbyname_r (const char *name, const char *protocol,
 	{
 	  enum nss_status status = niserr2nss (result->status);
 
+	  __set_errno (olderr);
+
 	  nis_freeresult (result);
 	  return status;
 	}
@@ -340,7 +343,10 @@ _nss_nisplus_getservbyname_r (const char *name, const char *protocol,
 	      return NSS_STATUS_TRYAGAIN;
 	    }
 	  else
-	    return NSS_STATUS_NOTFOUND;
+	    {
+	      __set_errno (olderr);
+	      return NSS_STATUS_NOTFOUND;
+	    }
 	}
       return NSS_STATUS_SUCCESS;
     }
@@ -369,6 +375,7 @@ _nss_nisplus_getservbyport_r (const int number, const char *protocol,
       int parse_res;
       nis_result *result;
       char buf[60 + strlen (protocol) + tablename_len];
+      int olderr = errno;
 
       sprintf (buf, "[port=%d,proto=%s],%s",
 	       number, protocol, tablename_val);
@@ -379,6 +386,8 @@ _nss_nisplus_getservbyport_r (const int number, const char *protocol,
 	{
 	  enum nss_status status = niserr2nss (result->status);
 
+	  __set_errno (olderr);
+
 	  nis_freeresult (result);
 	  return status;
 	}
@@ -395,7 +404,10 @@ _nss_nisplus_getservbyport_r (const int number, const char *protocol,
 	      return NSS_STATUS_TRYAGAIN;
 	    }
 	  else
-	    return NSS_STATUS_NOTFOUND;
+	    {
+	      __set_errno (olderr);
+	      return NSS_STATUS_NOTFOUND;
+	    }
 	}
       return NSS_STATUS_SUCCESS;
     }
diff --git a/nis/nss_nisplus/nisplus-spwd.c b/nis/nss_nisplus/nisplus-spwd.c
index 7d549f4b00..5cff1b7850 100644
--- a/nis/nss_nisplus/nisplus-spwd.c
+++ b/nis/nss_nisplus/nisplus-spwd.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1997, 2001 Free Software Foundation, Inc.
+/* Copyright (C) 1997, 2001, 2002 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1997.
 
@@ -186,6 +186,7 @@ _nss_nisplus_getspnam_r (const char *name, struct spwd *sp,
     {
       nis_result *result;
       char buf[strlen (name) + 24 + tablename_len];
+      int olderr = errno;
 
       sprintf (buf, "[name=%s],%s", name, tablename_val);
 
@@ -195,6 +196,8 @@ _nss_nisplus_getspnam_r (const char *name, struct spwd *sp,
 	{
 	  enum nss_status status = niserr2nss (result->status);
 
+	  __set_errno (olderr);
+
 	  nis_freeresult (result);
 	  return status;
 	}
@@ -211,7 +214,10 @@ _nss_nisplus_getspnam_r (const char *name, struct spwd *sp,
 	      return NSS_STATUS_TRYAGAIN;
 	    }
 	  else
-	    return NSS_STATUS_NOTFOUND;
+	    {
+	      __set_errno (olderr);
+	      return NSS_STATUS_NOTFOUND;
+	    }
 	}
       return NSS_STATUS_SUCCESS;
     }
diff --git a/nss/getXXbyYY_r.c b/nss/getXXbyYY_r.c
index 8358e2f71d..06aebb4ab0 100644
--- a/nss/getXXbyYY_r.c
+++ b/nss/getXXbyYY_r.c
@@ -229,7 +229,8 @@ done:
 #ifdef POSTPROCESS
   POSTPROCESS;
 #endif
-  return status == NSS_STATUS_SUCCESS ? 0 : errno;
+  return (status == NSS_STATUS_SUCCESS
+	  ? 0 : (status == NSS_STATUS_TRYAGAIN ? EAGAIN : ENOENT));
 }
 
 
diff --git a/nss/nss_files/files-XXX.c b/nss/nss_files/files-XXX.c
index da840595a4..b6b8cf8d34 100644
--- a/nss/nss_files/files-XXX.c
+++ b/nss/nss_files/files-XXX.c
@@ -1,5 +1,5 @@
 /* Common code for file-based databases in nss_files module.
-   Copyright (C) 1996, 1997, 1998, 1999, 2001 Free Software Foundation, Inc.
+   Copyright (C) 1996,1997,1998,1999,2001,2002 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -191,7 +191,6 @@ internal_getent (struct STRUCTURE *result,
       if (p == NULL)
 	{
 	  /* End of file or read error.  */
-	  *errnop = ENOENT;
 	  H_ERRNO_SET (HOST_NOT_FOUND);
 	  return NSS_STATUS_NOTFOUND;
 	}
diff --git a/resolv/nss_dns/dns-host.c b/resolv/nss_dns/dns-host.c
index fafe3435c0..c7bfc13aab 100644
--- a/resolv/nss_dns/dns-host.c
+++ b/resolv/nss_dns/dns-host.c
@@ -137,6 +137,7 @@ _nss_dns_gethostbyname2_r (const char *name, int af, struct hostent *result,
   int size, type, n;
   const char *cp;
   int map = 0;
+  int olderr = errno;
 
   if ((_res.options & RES_INIT) == 0 && __res_ninit (&_res) == -1)
     return NSS_STATUS_UNAVAIL;
@@ -175,7 +176,10 @@ _nss_dns_gethostbyname2_r (const char *name, int af, struct hostent *result,
       enum nss_status status = (errno == ECONNREFUSED
 				? NSS_STATUS_UNAVAIL : NSS_STATUS_NOTFOUND);
       *h_errnop = h_errno;
-      *errnop = h_errno == TRY_AGAIN ? EAGAIN : ENOENT;
+      if (h_errno == TRY_AGAIN)
+	*errnop = EAGAIN;
+      else
+	__set_errno (olderr);
 
       /* If we are looking for a IPv6 address and mapping is enabled
 	 by having the RES_USE_INET6 bit in _res.options set, we try
@@ -236,6 +240,7 @@ _nss_dns_gethostbyaddr_r (const void *addr, socklen_t len, int af,
   char qbuf[MAXDNAME+1], *qp = NULL;
   size_t size;
   int n, status;
+  int olderr = errno;
 
   if ((_res.options & RES_INIT) == 0 && __res_ninit (&_res) == -1)
     return NSS_STATUS_UNAVAIL;
@@ -300,7 +305,7 @@ _nss_dns_gethostbyaddr_r (const void *addr, socklen_t len, int af,
   if (n < 0)
     {
       *h_errnop = h_errno;
-      *errnop = errno;
+      __set_errno (olderr);
       return errno == ECONNREFUSED ? NSS_STATUS_UNAVAIL : NSS_STATUS_NOTFOUND;
     }
 
@@ -443,7 +448,6 @@ getanswer_r (const querybuf *answer, int anslen, const char *qname, int qtype,
   if (__builtin_expect (qdcount, 1) != 1)
     {
       *h_errnop = NO_RECOVERY;
-      *errnop = ENOENT;
       return NSS_STATUS_UNAVAIL;
     }
   if (sizeof (struct host_data) + (ancount + 1) * sizeof (char *) >= buflen)
diff --git a/resolv/nss_dns/dns-network.c b/resolv/nss_dns/dns-network.c
index 105b81f48b..88166531b3 100644
--- a/resolv/nss_dns/dns-network.c
+++ b/resolv/nss_dns/dns-network.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1996, 1997, 1998, 1999 Free Software Foundation, Inc.
+/* Copyright (C) 1996, 1997, 1998, 1999, 2002 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Extended from original form by Ulrich Drepper <drepper@cygnus.com>, 1996.
 
@@ -146,6 +146,7 @@ _nss_dns_getnetbyaddr_r (uint32_t net, int type, struct netent *result,
   char qbuf[MAXDNAME];
   int cnt, anslen;
   u_int32_t net2;
+  int olderr = errno;
 
   /* No net address lookup for IPv6 yet.  */
   if (type != AF_INET)
@@ -185,10 +186,11 @@ _nss_dns_getnetbyaddr_r (uint32_t net, int type, struct netent *result,
   if (anslen < 0)
     {
       /* Nothing found.  */
-      *errnop = errno;
-      return (errno == ECONNREFUSED
-	      || errno == EPFNOSUPPORT
-	      || errno == EAFNOSUPPORT)
+      int err = errno;
+      __set_errno (olderr);
+      return (err == ECONNREFUSED
+	      || err == EPFNOSUPPORT
+	      || err == EAFNOSUPPORT)
 	? NSS_STATUS_UNAVAIL : NSS_STATUS_NOTFOUND;
     }