getgrnam_r() — Search group database for a name

Standards

Standards / Extensions C or C++ Dependencies

Single UNIX Specification, Version 2
Single UNIX Specification, Version 3
z/OS® UNIX

both OS/390 V2R8

Format

#define _XOPEN_SOURCE 500
#include <sys/types.h>
#include <grp.h>

int getgrnam_r(const char *name, struct group *grp, char *buffer,
size_t bufsize, struct group **result);
 
#define _POSIX_SOURCE
#include <grp.h>

int __getgrnam1(const char *name, struct group *grp, char *buffer,
size_t bufsize, struct group **result);

General description

The getgrnam_r() function updates the group structure pointed to by grp and stores a pointer to that structure at the location pointed to by result. The structure contains an entry from the group database with a matching name. Storage referenced by the group structure is allocated from the memory provided with the buffer parameter, which is bufsize bytes in size. A NULL pointer is returned at the location pointed to by result on error or if the requested entry is not found.

The __getgrnam1() function is identical to getgrnam_r() except that it does not return the individual group member names. Element gr_mem within the group structure pointed to by grp will be set to NULL.

Returned value

If successful, getgrnam_r() or __getgrnam1() returns 0.

If unsuccessful, getgrnam_r() or _getgrnam1() returns an error number and sets errno to one of the following values:

Error Code
Description
EINVAL
One of the input arguments was not valid. Arguments grp, buffer, and result must not be NULL. Argument bufsize must not be 0.
ERANGE
Insufficient storage was supplied in buffer and bufsize to contain the data to be referenced by the resulting group structure.
EMVSSAFEXTRERR
The system authorization facility (SAF) RACROUTE EXTRACT service had an error.
EMVSSAF2ERR
The SAF Get GMAP service had an error.

Related information