getgroups -- Determine Supplementary Group IDs

SYNOPSIS

 #include <sys/types.h>
 #include <unistd.h>

 int getgroups(int listSize, gid_t *groupList);
 

DESCRIPTION

getgroups stores the supplementary group IDs of the calling process in an array.
listSize
is the number of elements that can be stored in the array.
groupList
is a pointer to the beginning of the array used to store the supplementary user IDs.

Note: groupList is declared as gid_t *groupList so that NULL may be passed to groupList when listSize is 0. This could not be done if groupList was declared as an array.

RETURN VALUE

getgroups returns the number of supplementary group IDs in groupList. This value is always less than or equal to the value of NGROUPS_MAX defined in <limits.h>. If listSize is 0, getgroups returns the total number of supplementary group IDs and does not store the group IDs in an array. getgroups returns a -1 if unsuccessful.

EXAMPLE

The following example illustrates the use of getgroups to determine supplementary group IDs.

Note: You must specify the posix option when compiling this example.

  #include <sys/types.h>
  #include <unistd.h>
  #include <stdio.h>
  #include <limits.h>


  main()
  {
     gid_t groupIDs[NGROUPS_MAX];
     int i, count;

     if ((count = getgroups(NGROUPS_MAX, groupIDs)) == -1)
        perror("getgroups error");
     else
        for (i = 0; i < count; i++)
           printf("Group ID %d = %dn", i + 1, (int) groupIDs[i]);
  }

 

RELATED FUNCTIONS

getgroupsbyname


Copyright (c) 1998 SAS Institute Inc. Cary, NC, USA. All rights reserved.