Go to main content

man pages section 3: Basic Library Functions

Exit Print View

Updated: Thursday, June 13, 2019
 
 

getgrouplist (3C)

Name

getgrouplist - obtain a list of group memberships of a user

Synopsis

#include <grp.h>

int getgrouplist(const char *user, gid_t group,
	gid_t *groups, int *ngroups);

Description

The getgrouplist() function takes user and group as arguments, along with groups and ngroups. user and group are taken from the user's password entry. group is a pointer to an array of gid_ts, and ngroups is a pointer to an integer holding the number of gid_ts in groups.

The getgrouplist() function fills in the given array group with the group IDs of all the groups to which the user belongs. *ngroups of these group IDs will be returned in the array groups. The resulting value of *ngroups will include group in the count. The overall value of ngroups can be greater than the number of group IDs stored in groups.

Before returning, the getgrouplist() function sets the integer variable pointed by ngroups to the number of group IDs found for the user. This is true even when the getgrouplist() function returns an error.

Return Values

The getgrouplist() function returns the new value *ngroups if it is less than or equal to the original value of *ngroups.

The getgrouplist() function returns -1 if the new value of *ngroups is greater than the original value. In other words, if the getgrouplist() function returns -1, there were more groups than the buffer at *group could hold. In this case, *ngroups retains its new value, and can be checked by the caller to facilitate a subsequent call to the getgrouplist() function with an appropriately sized array at *groups.

Attributes

See attributes(7) for descriptions of the following attributes:

ATTRIBUTE TYPE
ATTRIBUTE VALUE
Interface Stability
Committed
MT-Level
Safe

See Also

Intro(2), initgroups(3C), getgrnam(3C), getpwnam(3C), standards(7).

Notes

The getgroupslist() function is not specified by any standard, so will not be declared if a standard conformance macro is defined unless __EXTENSIONS__ is also defined. See standards(7) for details.

HISTORY

The getgrouplist() function was added to Oracle Solaris in the 11.2 SRU 10 release.