]> sourceware.org Git - glibc.git/commitdiff
shadow: Implement fgetspent_r using __nss_fgetent_r
authorFlorian Weimer <fweimer@redhat.com>
Thu, 16 Jul 2020 15:34:43 +0000 (17:34 +0200)
committerFlorian Weimer <fweimer@redhat.com>
Tue, 21 Jul 2020 05:34:43 +0000 (07:34 +0200)
Tested-by: Carlos O'Donell <carlos@redhat.com>
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
gshadow/tst-fgetsgent_r.c
shadow/fgetspent_r.c

index 780409afa9f0afd238f5dadfbe322405e5e928f9..f81e09b362c27e9bc854971ea0cc036358821e85 100644 (file)
@@ -168,6 +168,7 @@ run_test (const char *path, size_t buffer_size)
       free (result_storage);
     }
 
+  xfclose (fp);
   return resized;
 }
 
index da35846df03ff4db08d85cbbbd5ea7f3f0a8a29b..d4d4e52f6a367e36fc79c9d8d973bfcd35a534be 100644 (file)
@@ -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)
This page took 0.046001 seconds and 5 git commands to generate.