1 /* provide consistent interface to getgroups for systems that don't allow N==0
3 Copyright (C) 1996, 1999, 2003, 2006, 2007, 2008, 2009 Free
4 Software Foundation, Inc.
6 This program is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19 /* written by Jim Meyering */
31 /* Provide a stub that fails with ENOSYS, since there is no group
32 information available on mingw. */
34 getgroups (int n _UNUSED_PARAMETER_, GETGROUPS_T *groups _UNUSED_PARAMETER_)
40 #else /* HAVE_GETGROUPS */
44 /* On at least Ultrix 4.3 and NextStep 3.2, getgroups (0, NULL) always
45 fails. On other systems, it returns the number of supplemental
46 groups for the process. This function handles that special case
47 and lets the system-provided function handle all others. However,
48 it can fail with ENOMEM if memory is tight. It is unspecified
49 whether the effective group id is included in the list. */
52 rpl_getgroups (int n, GETGROUPS_T *group)
59 return getgroups (n, group);
64 /* No need to worry about address arithmetic overflow here,
65 since the ancient systems that we're running on have low
66 limits on the number of secondary groups. */
67 gbuf = malloc (n * sizeof *gbuf);
70 n_groups = getgroups (n, gbuf);
71 if (n_groups == -1 ? errno != EINVAL : n_groups < n)
84 #endif /* HAVE_GETGROUPS */