1 /* Copyright (C) 1991 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
16 not, write to the Free Software Foundation, Inc., 675 Mass Ave,
17 Cambridge, MA 02139, USA. */
25 #include <sys/types.h>
28 /* This is the function that all the others are based on.
29 The format of the group file is known only here. */
31 /* Structure containing info kept by each __grpread caller. */
35 #define PASSWD_SIZE 20
36 #define MEMLIST_SIZE 1000
37 char buf[NAME_SIZE + 1 + PASSWD_SIZE + 1 + 20 + 1 + 20 + MEMLIST_SIZE + 1];
44 /* Return a chunk of memory containing a pre-initialized `grpread_info'. */
46 DEFUN_VOID(__grpalloc)
48 grpread_info *info = (PTR) malloc(sizeof(grpread_info));
52 info->max_members = 5;
53 info->members = (char **) malloc(5 * sizeof(char *));
54 if (info->members == NULL)
63 /* Read a group entry from STREAM, filling in G. */
65 DEFUN(__grpread, (stream, g), FILE *stream AND PTR CONST g)
67 register grpread_info *CONST info = (grpread_info *) g;
78 if (fgets (info->buf, sizeof(info->buf), stream) == NULL)
82 end = strchr (start, ':');
86 info->g.gr_name = start;
89 end = strchr (start, ':');
93 info->g.gr_passwd = start;
95 info->g.gr_gid = (gid_t) strtol (end + 1, &end, 10);
103 end = strchr (start, ',');
106 end = strchr (start, '\n');
117 if (i == info->max_members - 2)
119 info->max_members += 5;
120 info->members = (char **)
121 realloc ((PTR) info->members, info->max_members * sizeof (char *));
122 if (info->members == NULL)
126 info->members[i++] = start;
127 } while (end != NULL);
128 info->members[i] = NULL;
129 info->g.gr_mem = info->members;