public inbox for glibc-cvs@sourceware.org
help / color / mirror / Atom feed
* [glibc] shadow: Implement fgetspent_r using __nss_fgetent_r
@ 2020-07-21  6:26 Florian Weimer
  0 siblings, 0 replies; only message in thread
From: Florian Weimer @ 2020-07-21  6:26 UTC (permalink / raw)
  To: glibc-cvs

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=00bc6830e3fe3f10495917afe0835ddd19133c6a

commit 00bc6830e3fe3f10495917afe0835ddd19133c6a
Author: Florian Weimer <fweimer@redhat.com>
Date:   Thu Jul 16 17:34:43 2020 +0200

    shadow: Implement fgetspent_r using __nss_fgetent_r
    
    Tested-by: Carlos O'Donell <carlos@redhat.com>
    Reviewed-by: Carlos O'Donell <carlos@redhat.com>

Diff:
---
 gshadow/tst-fgetsgent_r.c |  1 +
 shadow/fgetspent_r.c      | 43 ++++++-------------------------------------
 2 files changed, 7 insertions(+), 37 deletions(-)

diff --git a/gshadow/tst-fgetsgent_r.c b/gshadow/tst-fgetsgent_r.c
index 780409afa9..f81e09b362 100644
--- a/gshadow/tst-fgetsgent_r.c
+++ b/gshadow/tst-fgetsgent_r.c
@@ -168,6 +168,7 @@ run_test (const char *path, size_t buffer_size)
       free (result_storage);
     }
 
+  xfclose (fp);
   return resized;
 }
 
diff --git a/shadow/fgetspent_r.c b/shadow/fgetspent_r.c
index da35846df0..d4d4e52f6a 100644
--- a/shadow/fgetspent_r.c
+++ b/shadow/fgetspent_r.c
@@ -20,9 +20,6 @@
 #include <shadow.h>
 #include <stdio.h>
 
-#define flockfile(s) _IO_flockfile (s)
-#define funlockfile(s) _IO_funlockfile (s)
-
 /* Define a line parsing function using the common code
    used in the nss_files module.  */
 
@@ -39,39 +36,11 @@ int
 __fgetspent_r (FILE *stream, struct spwd *resbuf, char *buffer, size_t buflen,
 	       struct spwd **result)
 {
-  char *p;
-
-  flockfile (stream);
-  do
-    {
-      buffer[buflen - 1] = '\xff';
-      p = fgets_unlocked (buffer, buflen, stream);
-      if (p == NULL && feof_unlocked (stream))
-	{
-	  funlockfile (stream);
-	  *result = NULL;
-	  __set_errno (ENOENT);
-	  return errno;
-	}
-      if (p == NULL || buffer[buflen - 1] != '\xff')
-	{
-	  funlockfile (stream);
-	  *result = NULL;
-	  __set_errno (ERANGE);
-	  return errno;
-	}
-
-      /* Skip leading blanks.  */
-      while (isspace (*p))
-	++p;
-    } 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 (buffer, (void *) resbuf, NULL, 0, &errno));
-
-  funlockfile (stream);
-
-  *result = resbuf;
-  return 0;
+  int ret = __nss_fgetent_r (stream, resbuf, buffer, buflen, parse_line);
+  if (ret == 0)
+    *result = resbuf;
+  else
+    *result = NULL;
+  return ret;
 }
 weak_alias (__fgetspent_r, fgetspent_r)


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-07-21  6:26 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-21  6:26 [glibc] shadow: Implement fgetspent_r using __nss_fgetent_r Florian Weimer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).