getgroups.c

Print out the gids of all groups for the current user. [詳細]

ソースコードを見る。


関数

int main (UNUSED(int argc), UNUSED(char *argv[]))

説明

Print out the gids of all groups for the current user.

This is like `id -G` on Linux, but it's too hard to find a portable equivalent.

getgroups.c で定義されています。


関数

int main ( UNUSED(int argc)  ,
UNUSED(char *argv[])   
)

getgroups.c30 行で定義されています。

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:44 2009に生成されました。  doxygen 1.4.7