2 * Print out the gids of all groups for the current user. This is like
3 * `id -G` on Linux, but it's too hard to find a portable equivalent.
5 * Copyright (C) 2002 Martin Pool
6 * Copyright (C) 2003, 2004 Wayne Davison
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
26 main(UNUSED(int argc), UNUSED(char *argv[]))
34 if ((n = getgroups(0, NULL)) < 0) {
42 list = (gid_t*)malloc(sizeof (gid_t) * (n + 1));
44 fprintf(stderr, "out of memory!\n");
50 n = getgroups(n, list);
53 for (i = 0; i < n; i++) {
54 printf("%lu ", (unsigned long)list[i]);
58 /* The default gid might not be in the list on some systems. */
60 printf("%lu", (unsigned long)gid);