initgroups()

Initialize the supplementary group access list

Synopsis:

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

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

Arguments:

name
The name of the user whose group membership you want to use as the supplementary group access list.
basegid
A group ID that you want to include in the group access list.

Library:

libc

Use the -l c option to qcc to link against this library. This library is usually included automatically.

Description:

The initgroups() function reads the group membership for the user specified by name from the group database, and then initializes the supplementary group access list of the calling process (see getgrnam() and getgroups()).

Returns:

0
Success.
-1
An error occurred (errno is set).

Errors:

EPERM
The caller isn't root.

Files:

/etc/group
The group database.

Classification:

Unix

Safety:  
Cancellation point No
Interrupt handler No
Signal handler No
Thread No

Caveats:

If initgroups() fails, it doesn't change the supplementary group access list.

The getgrouplist() function called by initgroups() is based on getgrent(). If the calling process uses getgrent(), the in-memory group structure is overwritten in the call to initgroups().