1 /* -*- buffer-read-only: t -*- vi: set ro: */
2 /* DO NOT EDIT! GENERATED AUTOMATICALLY! */
3 /* provide consistent interface to getgroups for systems that don't allow N==0
5 Copyright (C) 1996, 1999, 2003, 2006-2014 Free Software Foundation, Inc.
7 This program is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 /* written by Jim Meyering */
32 /* Provide a stub that fails with ENOSYS, since there is no group
33 information available on mingw. */
35 getgroups (int n _GL_UNUSED, GETGROUPS_T *groups _GL_UNUSED)
41 #else /* HAVE_GETGROUPS */
44 # ifndef GETGROUPS_ZERO_BUG
45 # define GETGROUPS_ZERO_BUG 0
48 /* On OS X 10.6 and later, use the usual getgroups, not the one
49 supplied when _DARWIN_C_SOURCE is defined. _DARWIN_C_SOURCE is
50 normally defined, since it means "conform to POSIX, but add
51 non-POSIX extensions even if that violates the POSIX namespace
52 rules", which is what we normally want. But with getgroups there
53 is an inconsistency, and _DARWIN_C_SOURCE means "change getgroups()
54 so that it no longer works right". The BUGS section of compat(5)
55 says that the behavior is dubious if you compile different sections
56 of a program with different _DARWIN_C_SOURCE settings, so fix only
57 the offending symbol. */
59 int posix_getgroups (int, gid_t []) __asm ("_getgroups");
60 # define getgroups posix_getgroups
63 /* On at least Ultrix 4.3 and NextStep 3.2, getgroups (0, NULL) always
64 fails. On other systems, it returns the number of supplemental
65 groups for the process. This function handles that special case
66 and lets the system-provided function handle all others. However,
67 it can fail with ENOMEM if memory is tight. It is unspecified
68 whether the effective group id is included in the list. */
71 rpl_getgroups (int n, gid_t *group)
83 if (n != 0 || !GETGROUPS_ZERO_BUG)
86 if (sizeof *group == sizeof *gbuf)
87 return getgroups (n, (GETGROUPS_T *) group);
89 if (SIZE_MAX / sizeof *gbuf <= n)
94 gbuf = malloc (n * sizeof *gbuf);
97 result = getgroups (n, gbuf);
113 /* No need to worry about address arithmetic overflow here,
114 since the ancient systems that we're running on have low
115 limits on the number of secondary groups. */
116 gbuf = malloc (n * sizeof *gbuf);
119 n_groups = getgroups (n, gbuf);
120 if (n_groups == -1 ? errno != EINVAL : n_groups < n)
133 #endif /* HAVE_GETGROUPS */