getgrent man page on 4.4BSD

Man page or keyword search:  
man Server   1065 pages
apropos Keyword Search (all sections)
Output format
4.4BSD logo
[printable version]

GETGRENT(3)		 BSD Library Functions Manual		   GETGRENT(3)

     getgrent, getgrnam, getgrgid, setgroupent, setgrent, endgrent — group
     database operations

     #include <grp.h>

     struct group *

     struct group *
     getgrnam(const char *name);

     struct group *
     getgrgid(gid_t gid);

     struct group *
     setgroupent(int stayopen);



     These functions operate on the group database file /etc/group which is
     described in group(5).  Each line of the database is defined by the
     structure group found in the include file ⟨grp.h⟩:

	   struct group {
		   char	   *gr_name;	   /* group name */
		   char	   *gr_passwd;	   /* group password */
		   gid_t   gr_gid;	   /* group id */
		   char	   **gr_mem;	   /* group members */

     The functions getgrnam() and getgrgid() search the group database for the
     given group name pointed to by name or the group id pointed to by gid,
     respectively, returning the first one encountered.	 Identical group names
     or group gids may result in undefined behavior.

     The getgrent() function sequentially reads the group database and is
     intended for programs that wish to step through the complete list of

     All three routines will open the group file for reading, if necessary.

     The setgroupent() function opens the file, or rewinds it if it is already
     open.  If stayopen is non-zero, file descriptors are left open, signifi‐
     cantly speeding functions subsequent calls.  This functionality is unnec‐
     essary for getgrent() as it doesn't close its file descriptors by
     default.  It should also be noted that it is dangerous for long-running
     programs to use this functionality as the group file may be updated.

     The setgrent() function is identical to setgroupent() with an argument of

     The endgrent() function closes any open files.

     The functions getgrent(), getgrnam(), and getgrgid(), return a pointer to
     the group entry if successful; if end-of-file is reached or an error
     occurs a null pointer is returned.	 The functions setgroupent() and
     setgrent() return the value 1 if successful, otherwise the value 0 is
     returned.	The functions endgrent() and setgrfile() have no return value.

     /etc/group	 group database file

     getpwent(3), group(5)

     The functions endgrent(), getgrent(), getgrnam(), getgrgid(), and
     setgrent() appeared in Version 7 AT&T UNIX.  The functions setgrfile()
     and setgroupent() appeared in 4.3BSD-Reno.

     The historic function setgrfile(), which allowed the specification of
     alternate password databases, has been deprecated and is no longer avail‐

     The functions getgrent(), getgrnam(), getgrgid(), setgroupent() and
     setgrent() leave their results in an internal static object and return a
     pointer to that object. Subsequent calls to the same function will modify
     the same object.

     The functions getgrent(), endgrent(), setgroupent(), and setgrent() are
     fairly useless in a networked environment and should be avoided, if pos‐

BSD				April 19, 1994				   BSD

List of man pages available for 4.4BSD

Copyright (c) for man pages and the logo by the respective OS vendor.

For those who want to learn more, the polarhome community provides shell access and support.

[legal] [privacy] [GNU] [policy] [cookies] [netiquette] [sponsors] [FAQ]
Polarhome, production since 1999.
Member of Polarhome portal.
Based on Fawad Halim's script.
Vote for polarhome
Free Shell Accounts :: the biggest list on the net