1 /* provide consistent interface to getgroups for systems that don't allow N==0
3 Copyright (C) 1996, 1999, 2003, 2006 Free Software Foundation, Inc.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2, or (at your option)
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software Foundation,
17 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
19 /* written by Jim Meyering */
24 #include <sys/types.h>
30 /* On at least Ultrix 4.3 and NextStep 3.2, getgroups (0, 0) always fails.
31 On other systems, it returns the number of supplemental groups for the
32 process. This function handles that special case and lets the system-
33 provided function handle all others. */
36 getgroups (int n, GETGROUPS_T *group)
45 return getgroups (n, group);
50 /* No need to worry about address arithmetic overflow here,
51 since the ancient systems that we're running on have low
52 limits on the number of secondary groups. */
53 gbuf = xmalloc (n * sizeof *gbuf);
54 n_groups = getgroups (n, gbuf);