The Single UNIX ® Specification, Version 2
Copyright © 1997 The Open Group

 NAME

getgrgid, getgrgid_r - get group database entry for a group ID

 SYNOPSIS



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

struct group *getgrgid(gid_t gid);
int getgrgid_r(gid_t gid, struct group *grp, char *buffer,
    size_t bufsize, struct group **result);

 DESCRIPTION

The getgrgid() function searches the group database for an entry with a matching gid.

The getgrgid() interface need not be reentrant.

The getgrgid_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 gid. Storage referenced by the group structure is allocated from the memory provided with the buffer parameter, which is bufsize characters in size. The maximum size needed for this buffer can be determined with the {_SC_GETGR_R_SIZE_MAX} sysconf() parameter. A NULL pointer is returned at the location pointed to by result on error or if the requested entry is not found.

 RETURN VALUE

Upon successful completion, getgrgid() returns a pointer to a struct group with the structure defined in <grp.h> with a matching entry if one is found. The getgrgid() function returns a null pointer if either the requested entry was not found, or an error occurred. On error, errno will be set to indicate the error.

The return value may point to a static area which is overwritten by a subsequent call to getgrent(), getgrgid() or getgrnam().

If successful, the getgrgid_r() function returns zero. Otherwise, an error number is returned to indicate the error.

 ERRORS

The getgrgid() function may fail if:
[EIO]
An I/O error has occurred.
[EINTR]
A signal was caught during getgrgid().
[EMFILE]
{OPEN_MAX} file descriptors are currently open in the calling process.
[ENFILE]
The maximum allowable number of files is currently open in the system.

The getgrgid_r() function may fail if:

[ERANGE]
Insufficient storage was supplied via buffer and bufsize to contain the data to be referenced by the resulting group structure.

 EXAMPLES

None.

 APPLICATION USAGE

Applications wishing to check for error situations should set errno to 0 before calling getgrgid(). If errno is set on return, an error occurred.

 FUTURE DIRECTIONS

None.

 SEE ALSO

endgrent(), getgrnam(), <grp.h>, <limits.h>, <sys/types.h>.

DERIVATION

getgrgid() derived from System V Release 2.0.

getgrgid_r() derived from the POSIX Threads Extension (1003.1c-1995).


UNIX ® is a registered Trademark of The Open Group.
Copyright © 1997 The Open Group
[ Main Index | XSH | XCU | XBD | XCURSES | XNS ]