---
name: "initgroups"
section: "3"
platform: "macos"
package: "Libinfo"
version: "600"
release: "macOS 26.5"
platforms: ["linux", "freebsd", "macos"]
url: "https://new.carta.tech/initgroups"
---

# initgroups(3)

initialize group access list

## NAME

**initgroups** – initialize group access list

## LIBRARY

Standard system libraries.

## SYNOPSIS

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

*int*\

**initgroups**(*const char \*name*, *int basegid*);

## DESCRIPTION

The **initgroups**() function calculates a group access list for the user specified in *name*. This group list is then saved in the kernel credentials for the current process. The *basegid* is included in the groups list. Typically this value is given as the default group associated with the user's account record.

This function sets at most 16 group IDs in the process credentials. This list can be retrieved using the [getgroups(2)](/getgroups/2.md) function. Note that OS X supports group membership in an unlimited number of groups. The OS X kernel uses the group list stored in the process credentials only as an initial cache. Additional group memberships are determined by communication between the operating system and the **opendirectoryd** daemon.

Processes should not use the group ID numbers from [getgroups(2)](/getgroups/2.md) to determine a user's group membership. The list obtained from **getgroups**() may only be a partial list of a user's group membership. Membership checks should use the mbr\_gid\_to\_uuid(3), [mbr\_uid\_to\_uuid(3)](/mbr_uid_to_uuid/3.md), and [mbr\_check\_membership(3)](/mbr_check_membership/3.md) functions.

## RETURN VALUES

The **initgroups**() function returns 0 on success. On failure, this function will return -1 and set *errno* to one of the following values:

- \[EPERM\]

  The caller's effictive UID is not zero.

- \[EINVAL\]

  Internal error, an invalid array size was supplied to the kernel.

- \[EFAULT\]

  Internal error, invalid data was supplied to the kernel.

## SEE ALSO

[getgroups(2)](/getgroups/2.md), [getgrouplist(3)](/getgrouplist/3.md), mbr\_gid\_to\_uuid(3), [mbr\_uid\_to\_uuid(3)](/mbr_uid_to_uuid/3.md), [mbr\_check\_membership(3)](/mbr_check_membership/3.md).

## HISTORY

The **initgroups**() function appeared in 4.2BSD.
