|HP-UX Reference > G
getgrent(3C)HP-UX 11i Version 3: February 2007
getgrent(), getgrgid(), getgrgid_r(), getgrnam(), getgrnam_r(), setgrent(), endgrent(), fgetgrent() — get group file entry
#include <grp.h> struct group *getgrent(void); struct group *getgrgid(gid_t gid); int getgrgid_r(gid_t gid, struct group *grp, char *buffer, size_t buflen, struct group ** result); struct group *getgrnam(const char *name); int getgrnam_r(const char *name, struct group *grp, char *buffer, size_t buflen, struct group ** result); void setgrent(void); void endgrent(void); struct group *fgetgrent(FILE *stream);
getgrent(), getgrgid(), and getgrnam() are used to obtain group entries, and return a pointer to an object of group structure. An entry may come from any of the sources for group specified in the /etc/nsswitch.conf file. See nsswitch.conf(4).
The group structure is defined in <grp.h> and includes the following members:
char *gr_name; /* the name of the group */ char *gr_passwd; /* the encrypted group password */ gid_t gr_gid; /* the numerical group ID */ char **gr_mem; /* null-terminated array of pointers to member names */
getgrgid_r() and getgrnam_r() both update the struct group pointed to by grp and store a pointer to that structure at the location pointed to by result. The structure shall contain an entry from the group database with a matching gid or name. Storage referenced by the group structure pointed to by grp shall be allocated from the memory provided with the buffer parameter, which is buflen 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.
getgrent(), getgrgid(), getgrnam(), and fgetgrent() return a NULL pointer if an end-of-file or error is encountered on reading. Otherwise, the return value points to an internal static area containing a valid group structure.
getgrgid_r() and getgrnam_r() return zero upon success. Otherwise, an error number is returned to indicate the error.
getgrent(), getgrgid(), getgrnam() and fgetgrent() fail if any of the following are true:
The getgrgid_r() and getgrnam_r() functions will fail if:
The value returned by getgrent(), getgrgid(), getgrnam(), and fgetgrent() points to an area that is overwritten by each call to any of the functions. It must be copied if it is to be saved.
Users of getgrgid_r() and getgrnam_r() should note that these interfaces now conform with POSIX.1c. getgrent_r(), setgrent_r(), endgrent_r() and fgetgrent_r() are obsolescent interfaces. These interfaces and the old prototypes of getgrgid_r() and getgrnam_r() are supported for compatibility with existing DCE applications only.
The interfaces setgrent(), getgrent(), endgrent(), getgrgid(), getgrnam(), getgrgid_r() and getgrgnam_r() use the Dynamic Name Service Switch. (See nsswitch.conf(4).) An application that uses these interfaces cannot be fully archive bound.
ypcat(1), getgroups(2), getpwent(3C), stdio(3S), group(4), thread_safety(5).
getgrent(): SVID2, SVID3, XPG2
endgrent(): SVID2, SVID3, XPG2
fgetgrent(): SVID2, SVID3, XPG2
getgrgid(): AES, SVID2, SVID3, XPG2, XPG3, XPG4, FIPS 151-2, POSIX.1
getgrnam(): AES, SVID2, SVID3, XPG2, XPG3, XPG4, FIPS 151-2, POSIX.1
setgrent(): SVID2, SVID3, XPG2
getgrnam_r(), getgrgid_r(): POSIX.1c