---
name: "getgroups"
section: "2"
platform: "macos"
package: "xnu"
version: "12377.121.6"
release: "macOS 26.5"
platforms: ["linux", "freebsd", "macos"]
url: "https://new.carta.tech/getgroups"
---

# getgroups(2)

get group access list

## NAME

**getgroups** – get group access list

## SYNOPSIS

**#include \<unistd.h\>**

*int*\

**getgroups**(*int gidsetsize*, *gid\_t grouplist\[\]*);

## DESCRIPTION

**getgroups**() gets the current group access list of the current user process and stores it in the array  *grouplist\[\]*. The parameter *gidsetsize* indicates the number of entries that may be placed in  *grouplist\[\]*. **getgroups**() returns the actual number of groups returned in *grouplist\[\]*. However, no more than {NGROUPS\_MAX} will be returned. If *gidsetsize* is 0,  **getgroups**() returns the number of groups without modifying the *grouplist\[\]* array.

Calling [initgroups(3)](/initgroups/3.md) to opt-in for supplementary groups will cause **getgroups**() to return a single entry, the GID that was passed to  [initgroups(3)](/initgroups/3.md).

To provide compatibility with applications that use **getgroups**() in environments where users may be in more than {NGROUPS\_MAX} groups, a variant of **getgroups**(), obtained when compiling with either the macros \_DARWIN\_UNLIMITED\_GETGROUPS or \_DARWIN\_C\_SOURCE defined, can be used that is not limited to {NGROUPS\_MAX} groups. However, this variant only returns the user's default group access list and not the group list modified by a call to [setgroups(2)](/setgroups/2.md) (either in the current process or an ancestor process). Use of [setgroups(2)](/setgroups/2.md) is highly discouraged, and there is no foolproof way to determine if it has been previously called.

## RETURN VALUES

A successful call returns the number of groups in the group set. Otherwise, a value of -1 is returned and the global integer variable *errno* is set to indicate the error.

## ERRORS

The possible errors for **getgroups**() are:

- \[EFAULT\]

  The argument *grouplist* specifies an invalid address.

- \[EINVAL\]

  The argument *gidsetsize*, although non-zero, is smaller than the number of groups in the group set.

## LEGACY SYNOPSIS

**#include \<sys/param.h\>** **#include \<sys/types.h\>** **#include \<unistd.h\>**

The include files ⟨sys/param.h⟩ and ⟨sys/types.h⟩ are necessary.

## SEE ALSO

[setgroups(2)](/setgroups/2.md), [initgroups(3)](/initgroups/3.md), [compat(5)](/compat/5.md)

## HISTORY

The **getgroups**() function call appeared in 4.2BSD.
