about summary refs log tree commit diff
path: root/grp/fgetgrent.c
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>1999-06-07 20:17:36 +0000
committerUlrich Drepper <drepper@redhat.com>1999-06-07 20:17:36 +0000
commitdb873f322bdefd03e68e7196277aee44fc021791 (patch)
tree5bec02675f8b6fc1cfd729e2518ab620561c007b /grp/fgetgrent.c
parent15828e9d787fc2ff5d9bb277765bf6666f1563c3 (diff)
downloadglibc-db873f322bdefd03e68e7196277aee44fc021791.tar.gz
glibc-db873f322bdefd03e68e7196277aee44fc021791.tar.xz
glibc-db873f322bdefd03e68e7196277aee44fc021791.zip
Update.
1999-06-07  Ulrich Drepper  <drepper@cygnus.com>

	* grp/fgetgrent.c (fgetgrent): Remember position of stream before
	reading and reset in case the buffer was too small.

	* grp/fgetgrent_r.c (__fgetgrent_r): Set errno to ENOENT in case
	of EOF.
Diffstat (limited to 'grp/fgetgrent.c')
-rw-r--r--grp/fgetgrent.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/grp/fgetgrent.c b/grp/fgetgrent.c
index 24fdcd86d9..ac8d093f05 100644
--- a/grp/fgetgrent.c
+++ b/grp/fgetgrent.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991, 1996, 1997 Free Software Foundation, Inc.
+/* Copyright (C) 1991, 1996, 1997, 1999 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
@@ -19,6 +19,7 @@
 #include <errno.h>
 #include <grp.h>
 #include <bits/libc-lock.h>
+#include <stdio.h>
 #include <stdlib.h>
 
 
@@ -32,9 +33,13 @@ fgetgrent (FILE *stream)
   static char *buffer;
   static size_t buffer_size;
   static struct group resbuf;
+  fpos_t pos;
   struct group *result;
   int save;
 
+  if (fgetpos (stream, &pos) != 0)
+    return NULL;
+
   /* Get lock.  */
   __libc_lock_lock (lock);
 
@@ -61,6 +66,13 @@ fgetgrent (FILE *stream)
 	  __set_errno (save);
 	}
       buffer = new_buf;
+
+      /* Reset the stream.  */
+      if (fsetpos (stream, &pos) != 0)
+	{
+	  buffer = NULL;
+	  break;
+	}
     }
 
   if (buffer == NULL)