]> git.ipfire.org Git - thirdparty/glibc.git/blob - grp/fgetgrent_r.c
Update to 960810.
[thirdparty/glibc.git] / grp / fgetgrent_r.c
1 /* Copyright (C) 1991, 1996 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3
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.
8
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.
13
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
16 not, write to the Free Software Foundation, Inc., 675 Mass Ave,
17 Cambridge, MA 02139, USA. */
18
19 #include <ctype.h>
20 #include <grp.h>
21 #include <stdio.h>
22
23 /* Define a line parsing function using the common code
24 used in the nss_files module. */
25
26 #define STRUCTURE group
27 #define ENTNAME grent
28 struct grent_data {};
29
30 #define TRAILING_LIST_MEMBER gr_mem
31 #define TRAILING_LIST_SEPARATOR_P(c) ((c) == ',')
32 #include "../nss/nss_files/files-parse.c"
33 LINE_PARSER
34 (,
35 STRING_FIELD (result->gr_name, ISCOLON, 0);
36 STRING_FIELD (result->gr_passwd, ISCOLON, 0);
37 INT_FIELD (result->gr_gid, ISCOLON, 0, 10,);
38 )
39
40
41 /* Read one entry from the given stream. */
42 struct group *
43 __fgetgrent_r (FILE *stream, struct group *result, char *buffer, int buflen)
44 {
45 char *p;
46
47 do
48 {
49 p = fgets (buffer, buflen, stream);
50 if (p == NULL)
51 return NULL;
52
53 /* Skip leading blanks. */
54 while (isspace (*p))
55 ++p;
56 } while (*p == '\0' || *p == '#' || /* Ignore empty and comment lines. */
57 /* Parse the line. If it is invalid, loop to
58 get the next line of the file to parse. */
59 ! parse_line (p, result, (void *) buffer, buflen));
60
61 return result;
62 }
63 weak_alias (__fgetgrent_r, fgetgrent_r)