]>
git.ipfire.org Git - thirdparty/glibc.git/blob - grp/fgetgrent_r.c
1 /* Copyright (C) 1991, 1996, 1997, 1998 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public
15 License along with the GNU C Library; see the file COPYING.LIB. If not,
16 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 Boston, MA 02111-1307, USA. */
24 /* Define a line parsing function using the common code
25 used in the nss_files module. */
27 #define STRUCTURE group
31 #define TRAILING_LIST_MEMBER gr_mem
32 #define TRAILING_LIST_SEPARATOR_P(c) ((c) == ',')
33 #include <nss/nss_files/files-parse.c>
36 STRING_FIELD (result
->gr_name
, ISCOLON
, 0);
38 && (result
->gr_name
[0] == '+' || result
->gr_name
[0] == '-'))
40 result
->gr_passwd
= NULL
;
45 STRING_FIELD (result
->gr_passwd
, ISCOLON
, 0);
46 if (result
->gr_name
[0] == '+' || result
->gr_name
[0] == '-')
47 INT_FIELD_MAYBE_NULL (result
->gr_gid
, ISCOLON
, 0, 10, , 0)
49 INT_FIELD (result
->gr_gid
, ISCOLON
, 0, 10,)
54 /* Read one entry from the given stream. */
56 __fgetgrent_r (FILE *stream
, struct group
*resbuf
, char *buffer
, size_t buflen
,
57 struct group
**result
)
64 buffer
[buflen
- 1] = '\xff';
65 p
= fgets (buffer
, buflen
, stream
);
66 if (p
== NULL
&& feof (stream
))
71 if (p
== NULL
|| buffer
[buflen
- 1] != '\xff')
74 return errno
= ERANGE
;
77 /* Skip leading blanks. */
80 } while (*p
== '\0' || *p
== '#' /* Ignore empty and comment lines. */
81 /* Parse the line. If it is invalid, loop to
82 get the next line of the file to parse. */
83 || ! (parse_result
= parse_line (p
, resbuf
,
84 (void *) buffer
, buflen
,
87 if (parse_result
== -1)
89 /* The parser ran out of space. */
97 weak_alias (__fgetgrent_r
, fgetgrent_r
)