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-2007 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 version 2 as
10 * published by the Free Software Foundation.
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 along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
25 main(UNUSED(int argc), UNUSED(char *argv[]))
33 if ((n = getgroups(0, NULL)) < 0) {
41 list = (gid_t*)malloc(sizeof (gid_t) * (n + 1));
43 fprintf(stderr, "out of memory!\n");
49 n = getgroups(n, list);
52 for (i = 0; i < n; i++) {
53 printf("%lu ", (unsigned long)list[i]);
57 /* The default gid might not be in the list on some systems. */
59 printf("%lu", (unsigned long)gid);