|
|
786673 |
From 4f62a21d0ed19ff29bba704167179b862140d011 Mon Sep 17 00:00:00 2001
|
|
|
786673 |
From: Florian Weimer <fweimer@redhat.com>
|
|
|
786673 |
Date: Thu, 16 Jul 2020 17:28:28 +0200
|
|
|
786673 |
Subject: [PATCH 07/11] grp: Implement fgetgrent_r using __nss_fgetent_r
|
|
|
786673 |
|
|
|
786673 |
Tested-by: Carlos O'Donell <carlos@redhat.com>
|
|
|
786673 |
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
|
|
|
786673 |
---
|
|
|
786673 |
grp/fgetgrent_r.c | 54 ++++++------------------------------------------------
|
|
|
786673 |
1 file changed, 6 insertions(+), 48 deletions(-)
|
|
|
786673 |
|
|
|
786673 |
diff --git a/grp/fgetgrent_r.c b/grp/fgetgrent_r.c
|
|
|
786673 |
index 03daf4f..b598584 100644
|
|
|
786673 |
--- a/grp/fgetgrent_r.c
|
|
|
786673 |
+++ b/grp/fgetgrent_r.c
|
|
|
786673 |
@@ -20,10 +20,6 @@
|
|
|
786673 |
#include <grp.h>
|
|
|
786673 |
#include <stdio.h>
|
|
|
786673 |
|
|
|
786673 |
-#include <libio/iolibio.h>
|
|
|
786673 |
-#define flockfile(s) _IO_flockfile (s)
|
|
|
786673 |
-#define funlockfile(s) _IO_funlockfile (s)
|
|
|
786673 |
-
|
|
|
786673 |
/* Define a line parsing function using the common code
|
|
|
786673 |
used in the nss_files module. */
|
|
|
786673 |
|
|
|
786673 |
@@ -59,49 +55,11 @@ int
|
|
|
786673 |
__fgetgrent_r (FILE *stream, struct group *resbuf, char *buffer, size_t buflen,
|
|
|
786673 |
struct group **result)
|
|
|
786673 |
{
|
|
|
786673 |
- char *p;
|
|
|
786673 |
- int parse_result;
|
|
|
786673 |
-
|
|
|
786673 |
- flockfile (stream);
|
|
|
786673 |
- do
|
|
|
786673 |
- {
|
|
|
786673 |
- buffer[buflen - 1] = '\xff';
|
|
|
786673 |
- p = fgets_unlocked (buffer, buflen, stream);
|
|
|
786673 |
- if (__builtin_expect (p == NULL, 0) && feof_unlocked (stream))
|
|
|
786673 |
- {
|
|
|
786673 |
- funlockfile (stream);
|
|
|
786673 |
- *result = NULL;
|
|
|
786673 |
- __set_errno (ENOENT);
|
|
|
786673 |
- return errno;
|
|
|
786673 |
- }
|
|
|
786673 |
- if (__builtin_expect (p == NULL, 0) || buffer[buflen - 1] != '\xff')
|
|
|
786673 |
- {
|
|
|
786673 |
- funlockfile (stream);
|
|
|
786673 |
- *result = NULL;
|
|
|
786673 |
- __set_errno (ERANGE);
|
|
|
786673 |
- return errno;
|
|
|
786673 |
- }
|
|
|
786673 |
-
|
|
|
786673 |
- /* Skip leading blanks. */
|
|
|
786673 |
- while (isspace (*p))
|
|
|
786673 |
- ++p;
|
|
|
786673 |
- } while (*p == '\0' || *p == '#' /* Ignore empty and comment lines. */
|
|
|
786673 |
- /* Parse the line. If it is invalid, loop to
|
|
|
786673 |
- get the next line of the file to parse. */
|
|
|
786673 |
- || ! (parse_result = parse_line (p, resbuf,
|
|
|
786673 |
- (void *) buffer, buflen,
|
|
|
786673 |
- &errno)));
|
|
|
786673 |
-
|
|
|
786673 |
- funlockfile (stream);
|
|
|
786673 |
-
|
|
|
786673 |
- if (__builtin_expect (parse_result, 0) == -1)
|
|
|
786673 |
- {
|
|
|
786673 |
- /* The parser ran out of space. */
|
|
|
786673 |
- *result = NULL;
|
|
|
786673 |
- return errno;
|
|
|
786673 |
- }
|
|
|
786673 |
-
|
|
|
786673 |
- *result = resbuf;
|
|
|
786673 |
- return 0;
|
|
|
786673 |
+ int ret = __nss_fgetent_r (stream, resbuf, buffer, buflen, parse_line);
|
|
|
786673 |
+ if (ret == 0)
|
|
|
786673 |
+ *result = resbuf;
|
|
|
786673 |
+ else
|
|
|
786673 |
+ *result = NULL;
|
|
|
786673 |
+ return ret;
|
|
|
786673 |
}
|
|
|
786673 |
weak_alias (__fgetgrent_r, fgetgrent_r)
|
|
|
786673 |
--
|
|
|
786673 |
1.8.3.1
|
|
|
786673 |
|