summary refs log tree commit diff
path: root/grp/fgetgrent_r.c
diff options
context:
space:
mode:
Diffstat (limited to 'grp/fgetgrent_r.c')
-rw-r--r--grp/fgetgrent_r.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/grp/fgetgrent_r.c b/grp/fgetgrent_r.c
index 0c87815064..4abadfd569 100644
--- a/grp/fgetgrent_r.c
+++ b/grp/fgetgrent_r.c
@@ -21,6 +21,12 @@
 #include <grp.h>
 #include <stdio.h>
 
+#ifdef USE_IN_LIBIO
+# include <libio/iolibio.h>
+# define flockfile(s) _IO_flockfile (s)
+# define funlockfile(s) _IO_funlockfile (s)
+#endif
+
 /* Define a line parsing function using the common code
    used in the nss_files module.  */
 
@@ -59,17 +65,20 @@ __fgetgrent_r (FILE *stream, struct group *resbuf, char *buffer, size_t buflen,
   char *p;
   int parse_result;
 
+  flockfile (stream);
   do
     {
       buffer[buflen - 1] = '\xff';
-      p = fgets (buffer, buflen, stream);
-      if (p == NULL && feof (stream))
+      p = fgets_unlocked (buffer, buflen, stream);
+      if (p == NULL && feof_unlocked (stream))
 	{
+	  funlockfile (stream);
 	  *result = NULL;
 	  return errno;
 	}
       if (p == NULL || buffer[buflen - 1] != '\xff')
 	{
+	  funlockfile (stream);
 	  *result = NULL;
 	  return errno = ERANGE;
 	}
@@ -84,6 +93,8 @@ __fgetgrent_r (FILE *stream, struct group *resbuf, char *buffer, size_t buflen,
 					      (void *) buffer, buflen,
 					      &errno)));
 
+  funlockfile (stream);
+
   if (parse_result == -1)
     {
       /* The parser ran out of space.  */