Changed verbosity back from -vvvv to -vv.
[rsync/rsync.git] / getgroups.c
CommitLineData
4acbfa2a 1/*
0f78b815
WD
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.
4 *
5 * Copyright (C) 2002 Martin Pool
ba2133d6 6 * Copyright (C) 2003-2007 Wayne Davison
0f78b815 7 *
4acbfa2a 8 * This program is free software; you can redistribute it and/or modify
ba2133d6
WD
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
0f78b815 11 *
4acbfa2a
MP
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.
0f78b815 16 *
e7c67065
WD
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.
4acbfa2a
MP
20 */
21
4acbfa2a
MP
22#include "rsync.h"
23
f69204ad
WD
24int
25main(UNUSED(int argc), UNUSED(char *argv[]))
4acbfa2a
MP
26{
27 int n, i;
40ae4f93 28 gid_t *list;
670d8abf 29 gid_t gid = MY_GID();
58743a87 30 int gid_in_list = 0;
4acbfa2a 31
4f5b0756 32#ifdef HAVE_GETGROUPS
40ae4f93 33 if ((n = getgroups(0, NULL)) < 0) {
4acbfa2a
MP
34 perror("getgroups");
35 return 1;
36 }
1df395f7
WD
37#else
38 n = 0;
39#endif
4acbfa2a 40
40ae4f93
WD
41 list = (gid_t*)malloc(sizeof (gid_t) * (n + 1));
42 if (!list) {
43 fprintf(stderr, "out of memory!\n");
44 exit(1);
45 }
46
4f5b0756 47#ifdef HAVE_GETGROUPS
40ae4f93
WD
48 if (n > 0)
49 n = getgroups(n, list);
50#endif
51
58743a87 52 for (i = 0; i < n; i++) {
f358487f 53 printf("%lu ", (unsigned long)list[i]);
58743a87
WD
54 if (list[i] == gid)
55 gid_in_list = 1;
56 }
57 /* The default gid might not be in the list on some systems. */
58 if (!gid_in_list)
59 printf("%lu", (unsigned long)gid);
4acbfa2a 60 printf("\n");
0f78b815 61
4acbfa2a
MP
62 return 0;
63}