getgroups Subroutine

Purpose

Gets the supplementary group ID of the current process.

Library

Standard C Library (libc.a)

Syntax

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

int getgroups (NGroups, GIDSet)
int  NGroups;
gid_t  GIDSet [ ];

Description

The getgroups subroutine gets the supplementary group ID of the process. The list is stored in the array pointed to by the GIDSet parameter. The NGroups parameter indicates the number of entries that can be stored in this array. The getgroups subroutine never returns more than the number of entries specified by the NGROUPS_MAX constant. (The NGROUPS_MAX constant is defined in the limits.h file.) If the value in the NGroups parameter is 0, the getgroups subroutine returns the number of groups in the supplementary group.

Parameters

Item Description
GIDSet Points to the array in which the supplementary group ID of the user's process is stored.
NGroups Indicates the number of entries that can be stored in the array pointed to by the GIDSet parameter.

Return Values

Upon successful completion, the getgroups subroutine returns the number of elements stored into the array pointed to by the GIDSet parameter. If the getgroups subroutine is unsuccessful, a value of -1 is returned and the errno global variable is set to indicate the error.

Error Codes

The getgroups subroutine is unsuccessful if either of the following error codes is true:

Item Description
EFAULT The NGroups and GIDSet parameters specify an array that is partially or completely outside of the allocated address space of the process.
EINVAL The NGroups parameter is smaller than the number of groups in the supplementary group.