about summary refs log tree commit diff
path: root/shadow
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>1999-06-09 12:01:54 +0000
committerUlrich Drepper <drepper@redhat.com>1999-06-09 12:01:54 +0000
commite1c6ee839d13d57a4756e506a6b03f6a82b86d61 (patch)
treed8165cba8422ceb1f1871704ab322995593ac4ab /shadow
parentc41baa797637904ab405f14b78e722176abbdca1 (diff)
downloadglibc-e1c6ee839d13d57a4756e506a6b03f6a82b86d61.tar.gz
glibc-e1c6ee839d13d57a4756e506a6b03f6a82b86d61.tar.xz
glibc-e1c6ee839d13d57a4756e506a6b03f6a82b86d61.zip
Update.
1999-06-09  Ulrich Drepper  <drepper@cygnus.com>

	* pwd/fgetpwent_r.c: Set errno in the correct way.
	* shadow/fgetspent_r.c: Likewise.
	* pwd/fgetpwent.c: Handle long lines correctly.  Little
	optimizations.  Free static buffer when debugging memory handling.
	* shadow/fgetspent.c: Likewise.

	* grp/fgetgrent.c: Little optimization in loop.

1999-06-09  Andreas Jaeger  <aj@arthur.rhein-neckar.de>

	* grp/tst_fgetgrent.c (write_group): Fix generation of long line
	in a different way.
Diffstat (limited to 'shadow')
-rw-r--r--shadow/fgetspent.c29
-rw-r--r--shadow/fgetspent_r.c5
2 files changed, 28 insertions, 6 deletions
diff --git a/shadow/fgetspent.c b/shadow/fgetspent.c
index 902c95eb04..66a5452678 100644
--- a/shadow/fgetspent.c
+++ b/shadow/fgetspent.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1996, 1997 Free Software Foundation, Inc.
+/* Copyright (C) 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 <bits/libc-lock.h>
 #include <shadow.h>
+#include <stdio.h>
 #include <stdlib.h>
 
 
@@ -28,16 +29,21 @@
 /* We need to protect the dynamic buffer handling.  */
 __libc_lock_define_initialized (static, lock);
 
+static char *buffer;
+
 /* Read one shadow entry from the given stream.  */
 struct spwd *
 fgetspent (FILE *stream)
 {
-  static char *buffer;
   static size_t buffer_size;
   static struct spwd resbuf;
+  fpos_t pos;
   struct spwd *result;
   int save;
 
+  if (fgetpos (stream, &pos) != 0)
+    return NULL;
+
   /* Get lock.  */
   __libc_lock_lock (lock);
 
@@ -49,8 +55,8 @@ fgetspent (FILE *stream)
     }
 
   while (buffer != NULL
-	 && __fgetspent_r (stream, &resbuf, buffer, buffer_size, &result) != 0
-	 && errno == ERANGE)
+	 && (__fgetspent_r (stream, &resbuf, buffer, buffer_size, &result)
+	     == ERANGE))
     {
       char *new_buf;
       buffer_size += BUFLEN_SPWD;
@@ -64,6 +70,10 @@ fgetspent (FILE *stream)
 	  __set_errno (save);
 	}
       buffer = new_buf;
+
+      /* Reset the stream.  */
+      if (fsetpos (stream, &pos) != 0)
+	buffer = NULL;
     }
 
   if (buffer == NULL)
@@ -76,3 +86,14 @@ fgetspent (FILE *stream)
 
   return result;
 }
+
+
+/* Free all resources if necessary.  */
+static void __attribute__ ((unused))
+free_mem (void)
+{
+  if (buffer != NULL)
+    free (buffer);
+}
+
+text_set_element (__libc_subfreeres, free_mem);
diff --git a/shadow/fgetspent_r.c b/shadow/fgetspent_r.c
index 50d1fd9972..a61483c95a 100644
--- a/shadow/fgetspent_r.c
+++ b/shadow/fgetspent_r.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1996, 1997, 1998 Free Software Foundation, Inc.
+/* Copyright (C) 1996, 1997, 1998, 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
@@ -59,7 +59,8 @@ __fgetspent_r (FILE *stream, struct spwd *resbuf, char *buffer, size_t buflen,
 	{
 	  funlockfile (stream);
 	  *result = NULL;
-	  return errno = ERANGE;
+	  __set_errno (ERANGE);
+	  return errno;
 	}
 
       /* Skip leading blanks.  */