about summary refs log tree commit diff
path: root/grp
diff options
context:
space:
mode:
Diffstat (limited to 'grp')
-rw-r--r--grp/fgetgrent.c8
-rw-r--r--grp/fgetgrent_r.c15
-rw-r--r--grp/grp.h36
-rw-r--r--grp/testgrp.c2
4 files changed, 35 insertions, 26 deletions
diff --git a/grp/fgetgrent.c b/grp/fgetgrent.c
index 95ae2ecd6a..66dd305b0b 100644
--- a/grp/fgetgrent.c
+++ b/grp/fgetgrent.c
@@ -25,7 +25,11 @@ struct group *
 fgetgrent (FILE *stream)
 {
   static char buffer[BUFSIZ];
-  static struct group result;
+  static struct group resbuf;
+  struct group *result;
 
-  return __fgetgrent_r (stream, &result, buffer, sizeof buffer);
+  if (__fgetgrent_r (stream, &resbuf, buffer, sizeof buffer, &result) != 0)
+    return NULL;
+
+  return result;
 }
diff --git a/grp/fgetgrent_r.c b/grp/fgetgrent_r.c
index d8a8bfb2e1..e9a2c25a5a 100644
--- a/grp/fgetgrent_r.c
+++ b/grp/fgetgrent_r.c
@@ -42,8 +42,9 @@ LINE_PARSER
 
 
 /* Read one entry from the given stream.  */
-struct group *
-__fgetgrent_r (FILE *stream, struct group *result, char *buffer, int buflen)
+int
+__fgetgrent_r (FILE *stream, struct group *resbuf, char *buffer, size_t buflen,
+	       struct group **result)
 {
   char *p;
 
@@ -51,7 +52,10 @@ __fgetgrent_r (FILE *stream, struct group *result, char *buffer, int buflen)
     {
       p = fgets (buffer, buflen, stream);
       if (p == NULL)
-	return NULL;
+	{
+	  *result = NULL;
+	  return errno;
+	}
 
       /* Skip leading blanks.  */
       while (isspace (*p))
@@ -59,8 +63,9 @@ __fgetgrent_r (FILE *stream, struct group *result, char *buffer, int buflen)
     } while (*p == '\0' || *p == '#' ||	/* Ignore empty and comment lines.  */
 	     /* Parse the line.  If it is invalid, loop to
 		get the next line of the file to parse.  */
-	     ! parse_line (p, result, (void *) buffer, buflen));
+	     ! parse_line (p, resbuf, (void *) buffer, buflen));
 
-  return result;
+  *result = resbuf;
+  return 0;
 }
 weak_alias (__fgetgrent_r, fgetgrent_r)
diff --git a/grp/grp.h b/grp/grp.h
index 6a88191380..c03772cb34 100644
--- a/grp/grp.h
+++ b/grp/grp.h
@@ -51,7 +51,7 @@ extern FILE *__grpopen __P ((void));
 
 /* Read a group entry from STREAM, filling in G.
    Return the `struct group' of G if successful, NULL on failure.  */
-extern struct group *__grpread __P ((FILE * __stream, __ptr_t __g));
+extern struct group *__grpread __P ((FILE *__stream, __ptr_t __g));
 
 /* Return a chunk of memory containing pre-initialized data for __grpread.  */
 extern __ptr_t __grpalloc __P ((void));
@@ -76,7 +76,7 @@ extern struct group *getgrent __P ((void));
 
 #ifdef	__USE_SVID
 /* Read a group entry from STREAM.  */
-extern struct group *fgetgrent __P ((FILE * __stream));
+extern struct group *fgetgrent __P ((FILE *__stream));
 #endif
 
 /* Search for an entry with a matching group ID.  */
@@ -96,28 +96,28 @@ extern struct group *getgrnam __P ((__const char *__name));
    may change in later versions of this library.  */
 
 #if defined(__USE_SVID) || defined(__USE_MISC) || defined (__USE_BSD)
-extern struct group *getgrent_r __P ((struct group *__resultbuf,
-				      char *buffer, int __buflen));
+extern int getgrent_r __P ((struct group *__resultbuf, char *buffer,
+			    size_t __buflen, struct group **__result));
 #endif
 
 /* Search for an entry with a matching group ID.  */
-extern struct group *getgrgid_r __P ((__gid_t __gid,
-				      struct group *__resultbuf,
-				      char *buffer, int __buflen));
+extern int getgrgid_r __P ((__gid_t __gid, struct group *__resultbuf,
+			    char *buffer, size_t __buflen,
+			    struct group **__result));
 
 /* Search for an entry with a matching group name.  */
-extern struct group *getgrnam_r __P ((__const char *__name,
-				      struct group *__resultbuf,
-				      char *buffer, int __buflen));
+extern int getgrnam_r __P ((__const char *__name, struct group *__resultbuf,
+			    char *buffer, size_t __buflen,
+			    struct group **__result));
 
 #ifdef	__USE_SVID
 /* Read a group entry from STREAM.  */
-extern struct group *__fgetgrent_r __P ((FILE * __stream,
-					 struct group *__resultbuf,
-					 char *buffer, int __buflen));
-extern struct group *fgetgrent_r __P ((FILE * __stream,
-				       struct group *__resultbuf,
-				       char *buffer, int __buflen));
+extern int __fgetgrent_r __P ((FILE * __stream, struct group *__resultbuf,
+			       char *buffer, size_t __buflen,
+			       struct group **__result));
+extern int fgetgrent_r __P ((FILE * __stream, struct group *__resultbuf,
+			     char *buffer, size_t __buflen,
+			     struct group **__result));
 #endif
 
 #endif	/* reentrant */
@@ -129,12 +129,12 @@ extern struct group *fgetgrent_r __P ((FILE * __stream,
 #include <stddef.h>
 
 /* Set the group set for the current user to GROUPS (N of them).  */
-extern int setgroups __P ((size_t __n, __const __gid_t * groups));
+extern int setgroups __P ((size_t __n, __const __gid_t *__groups));
 
 /* Initialize the group set for the current user
    by reading the group database and using all groups
    of which USER is a member.  Also include GROUP.  */
-extern int initgroups __P ((__const char *user, __gid_t group));
+extern int initgroups __P ((__const char *__user, __gid_t __group));
 
 #endif /* Use BSD.  */
 
diff --git a/grp/testgrp.c b/grp/testgrp.c
index 3fac6b9bbf..62ba4e4a62 100644
--- a/grp/testgrp.c
+++ b/grp/testgrp.c
@@ -10,7 +10,7 @@ main (int argc, char *argv[])
 {
   uid_t me;
   struct passwd *my_passwd;
-  struct group *my_group;
+  struct group *my_group = NULL;
   char **members;
 
   me = getuid ();