Chapter Contents

Previous

Next
getgroups

getgroups



Determine Supplementary Group IDs

Portability: POSIX.1 conforming


SYNOPSIS
DESCRIPTION
RETURN VALUE
EXAMPLE
RELATED FUNCTIONS


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:    Note that 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.  [cautionend]


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.  [cautionend]

#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 = %d\n", i + 1, (int) groupIDs[i]);
}


RELATED FUNCTIONS

getgroupsbyname


Chapter Contents

Previous

Next

Top of Page

Copyright © 2001 by SAS Institute Inc., Cary, NC, USA. All rights reserved.