about summary refs log tree commit diff
path: root/pwd
diff options
context:
space:
mode:
Diffstat (limited to 'pwd')
-rw-r--r--pwd/getpwnam.c26
-rw-r--r--pwd/getpwuid.c26
-rw-r--r--pwd/pwd.h8
-rw-r--r--pwd/pwdread.c33
4 files changed, 51 insertions, 42 deletions
diff --git a/pwd/getpwnam.c b/pwd/getpwnam.c
index 1e7ea5c891..bac8b6b4da 100644
--- a/pwd/getpwnam.c
+++ b/pwd/getpwnam.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991 Free Software Foundation, Inc.
+/* Copyright (C) 1991, 1995 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
@@ -24,27 +24,13 @@ Cambridge, MA 02139, USA.  */
 
 /* Search for an entry with a matching name.  */
 struct passwd *
-DEFUN(getpwnam, (name), register CONST char *name)
+DEFUN(getpwnam, (name), const char *name)
 {
-  static PTR info = NULL;
-  register FILE *stream;
-  register struct passwd *p;
-
-  if (info == NULL)
+  int match (struct passwd *p)
     {
-      info = __pwdalloc();
-      if (info == NULL)
-	return(NULL);
+      return ! strcmp (name, p->pw_name);
     }
+  static void *info;
 
-  stream = __pwdopen();
-  if (stream == NULL)
-    return(NULL);
-
-  while ((p = __pwdread(stream, info)) != NULL)
-    if (!strcmp(p->pw_name, name))
-      break;
-
-  (void) fclose(stream);
-  return(p);
+  return __pwdscan (&info, &match);
 }
diff --git a/pwd/getpwuid.c b/pwd/getpwuid.c
index 30e40322db..5093488557 100644
--- a/pwd/getpwuid.c
+++ b/pwd/getpwuid.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991 Free Software Foundation, Inc.
+/* Copyright (C) 1991, 1995 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
@@ -24,27 +24,13 @@ Cambridge, MA 02139, USA.  */
 
 /* Search for an entry with a matching uid.  */
 struct passwd *
-DEFUN(getpwuid, (uid), register uid_t uid)
+DEFUN(getpwuid, (uid), uid_t uid)
 {
-  static PTR info;
-  register FILE *stream;
-  register struct passwd *p;
-
-  if (info == NULL)
+  int match (struct passwd *p)
     {
-      info = __pwdalloc();
-      if (info == NULL)
-	return(NULL);
+      return p->pw_uid == uid;
     }
+  static void *info;
 
-  stream = __pwdopen();
-  if (stream == NULL)
-    return(NULL);
-
-  while ((p = __pwdread(stream, info)) != NULL)
-    if (p->pw_uid == uid)
-      break;
-
-  (void) fclose(stream);
-  return(p);
+  return __pwdscan (&info, &match);
 }
diff --git a/pwd/pwd.h b/pwd/pwd.h
index c72c37df40..dd7d837b1e 100644
--- a/pwd/pwd.h
+++ b/pwd/pwd.h
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991, 1992 Free Software Foundation, Inc.
+/* Copyright (C) 1991, 1992, 1995 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
@@ -58,6 +58,12 @@ extern struct passwd *__pwdread __P ((FILE * __stream, __ptr_t __p));
 
 /* Return a chunk of memory containing pre-initialized data for __pwdread.  */
 extern __ptr_t __pwdalloc __P ((void));
+
+/* Scan the password file, filling in P, until SELECTOR returns nonzero for
+   an entry.  Return the `struct passwd' of P if successful, NULL on
+   failure.  */
+extern struct passwd *__pwdscan __P ((__ptr_t *__p,
+				      int (*__selector) (struct passwd *)));
 #endif
 
 
diff --git a/pwd/pwdread.c b/pwd/pwdread.c
index 0ce27d77b9..12032367fa 100644
--- a/pwd/pwdread.c
+++ b/pwd/pwdread.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991, 1992 Free Software Foundation, Inc.
+/* Copyright (C) 1991, 1992, 1995 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
@@ -114,3 +114,34 @@ DEFUN(__pwdread, (stream, p), FILE *stream AND PTR CONST p)
 
   return &info->p;
 }
+
+
+struct passwd *
+__pwdscan (void **info, int (*selector) (struct passwd *))
+{
+  FILE *stream;
+  struct passwd *p;
+
+  if (*info == NULL)
+    {
+      *info = __pwdalloc ();
+      if (info == NULL)
+	return NULL;
+    }
+
+  stream = __pwdopen ();
+  if (stream == NULL)
+    return NULL;
+
+  p = NULL;
+  while (! feof (stream))
+    {
+      p = __pwdread (stream, *info);
+      if (p && (*selector) (p))
+	break;
+      p = NULL;
+    }
+
+  (void) fclose (stream);
+  return p;
+}