getgroups.c

説明を見る。
00001 /*
00002  * Copyright (C) 2002 by Martin Pool
00003  * 
00004  * This program is free software; you can redistribute it and/or modify
00005  * it under the terms of the GNU General Public License as published by
00006  * the Free Software Foundation; either version 2 of the License, or
00007  * (at your option) any later version.
00008  * 
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  * 
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00017  */
00018 
00019 /**
00020  * @file getgroups.c
00021  *
00022  * Print out the gids of all groups for the current user.  This is
00023  * like `id -G` on Linux, but it's too hard to find a portable
00024  * equivalent.
00025  **/
00026 
00027 #include "rsync.h"
00028 
00029 int
00030 main(UNUSED(int argc), UNUSED(char *argv[]))
00031 {
00032         int n, i;
00033         gid_t *list;
00034         gid_t gid = MY_GID();
00035         int gid_in_list = 0;
00036 
00037 #ifdef HAVE_GETGROUPS
00038         if ((n = getgroups(0, NULL)) < 0) {
00039                 perror("getgroups");
00040                 return 1;
00041         }
00042 #else
00043         n = 0;
00044 #endif
00045 
00046         list = (gid_t*)malloc(sizeof (gid_t) * (n + 1));
00047         if (!list) {
00048                 fprintf(stderr, "out of memory!\n");
00049                 exit(1);
00050         }
00051 
00052 #ifdef HAVE_GETGROUPS
00053         if (n > 0)
00054                 n = getgroups(n, list);
00055 #endif
00056 
00057         for (i = 0; i < n; i++)  {
00058                 printf("%lu ", (unsigned long)list[i]);
00059                 if (list[i] == gid)
00060                         gid_in_list = 1;
00061         }
00062         /* The default gid might not be in the list on some systems. */
00063         if (!gid_in_list)
00064                 printf("%lu", (unsigned long)gid);
00065         printf("\n");
00066                 
00067         return 0;
00068 }

rsyncに対してSat Dec 5 19:45:41 2009に生成されました。  doxygen 1.4.7