about summary refs log tree commit diff
path: root/grp/grpread.c
diff options
context:
space:
mode:
Diffstat (limited to 'grp/grpread.c')
-rw-r--r--grp/grpread.c33
1 files changed, 32 insertions, 1 deletions
diff --git a/grp/grpread.c b/grp/grpread.c
index b7bac4c192..1fed32f2e3 100644
--- a/grp/grpread.c
+++ b/grp/grpread.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
@@ -133,3 +133,34 @@ DEFUN(__grpread, (stream, g), FILE *stream AND PTR CONST g)
 
   return &info->g;
 }
+
+
+struct group *
+__grpscan (void **info, int (*selector) (struct group *))
+{
+  FILE *stream;
+  struct group *p;
+
+  if (*info == NULL)
+    {
+      *info = __grpalloc ();
+      if (info == NULL)
+	return NULL;
+    }
+
+  stream = __grpopen ();
+  if (stream == NULL)
+    return NULL;
+
+  p = NULL;
+  while (! feof (stream))
+    {
+      p = __grpread (stream, *info);
+      if (p && (*selector) (p))
+	break;
+      p = NULL;
+    }
+
+  (void) fclose (stream);
+  return p;
+}