Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

endgrent, getgrent, setgrent - group management

&pagelevel(4)&pagelevel

Syntax

#include <grp.h>

void endgrent (void);

void setgrent (void);

struct group *getgrent (void); 

Description

getgrent() returns a pointer to an object with the structure shown below, which contains
the individual fields of a line of the /etc/group file. Each line contains an object of the
group structure, which is declared in the header file grp.h, with the following elements:

struct        group {
     char    *gr_name;       /* Name of the group */
     char    *gr_passwd;     /* Encoded group password */
     gid_t    gr_gid;        /* Numerical group ID */
     char   **gr_mem;        /* Pointer to names of the group members*/
};

getgrent() returns a pointer to the first group structure in the file the first time it is called;
after this it returns a pointer to the next group structure in the file. In this way, consecutive
calls can be used to search through the entire file.

setgrent() resets the file position indicator to the beginning of the group file, thus making
a repeat search possible.

endgrent() can be called at the end of processing in order to close the group file.

endgrent(), getgrent() and setgrent() are not thread-safe.

Return val.

getgrent():

Pointer to the first group structure of the group file

at the first call

Pointer to the next group structure of the group file



at subsequent calls

 

Null pointer

at EOF or if an error occurs. errno is set to indicate the error.

Errors

getgrent() will fail if: 

 

EINTR

EIO

EMFILE

ENFILE

getgrent() was interrupted by a signal.

an I/O error occurred during reading or writing.

The calling process contains {OPEN_MAX} open file descriptors.

The maximum permissible number of files is open in the system.

 

Extension

 

ENOMEM

There is not enough memory for storing the global data of getgrent(). (End)

Notes

The return value of getgrent() can point to an area that will be overwritten by a subsequent
call of getgrgid(), getgrnam() or getgrent().

These functions continue to be offered because they were common in the past. However,
the format of the group structure depends on the implementation, which is why applications
that use these functions are not portable. Portable applications should therefore use
getgrnam() and getgrgid()

See also

getgrgid(), getgrnam(), getlogin(), getpwent(), grp.h.