getgrnam, getgrnam_r, getgrgid, getgrgid_r - get group file entry


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

   struct group *getgrnam(const char *name);

   struct group *getgrgid(gid_t gid);

   int getgrnam_r(const char *name, struct group *grp,
             char *buf, size_t buflen, struct group **result);

   int getgrgid_r(gid_t gid, struct group *grp,
             char *buf, size_t buflen, struct group **result);

   Feature Test Macro Requirements for glibc (see feature_test_macros(7)):

   getgrnam_r(), getgrgid_r():
           || /* Glibc versions <= 2.19: */ _BSD_SOURCE || _SVID_SOURCE


   The getgrnam() function returns a pointer to a structure containing the
   broken-out fields of the record in the group database (e.g., the  local
   group file /etc/group, NIS, and LDAP) that matches the group name name.

   The getgrgid() function returns a pointer to a structure containing the
   broken-out fields of the record in the group database that matches  the
   group ID gid.

   The group structure is defined in <grp.h> as follows:

       struct group {
           char   *gr_name;        /* group name */
           char   *gr_passwd;      /* group password */
           gid_t   gr_gid;         /* group ID */
           char  **gr_mem;         /* NULL-terminated array of pointers
                                      to names of group members */

   For more information about the fields of this structure, see group(5).

   The getgrnam_r() and getgrgid_r() functions obtain the same information
   as getgrnam() and getgrgid(), but store the retrieved  group  structure
   in  the  space  pointed to by grp.  The string fields pointed to by the
   members of the group structure are stored in the  buffer  buf  of  size
   buflen.   A pointer to the result (in case of success) or NULL (in case
   no entry was found or an error occurred) is stored in *result.

   The call


   returns either -1, without changing errno, or an initial suggested size
   for  buf.   (If  this size is too small, the call fails with ERANGE, in
   which case the caller can retry with a larger buffer.)


   The getgrnam() and getgrgid() functions return a  pointer  to  a  group
   structure,  or  NULL  if  the  matching  entry is not found or an error
   occurs.  If an error occurs, errno is set appropriately.  If one  wants
   to  check  errno  after  the  call, it should be set to zero before the

   The return value may point to a static area, and may be overwritten  by
   subsequent  calls  to  getgrent(3), getgrgid(), or getgrnam().  (Do not
   pass the returned pointer to free(3).)

   On success, getgrnam_r() and getgrgid_r() return zero, and set  *result
   to  grp.  If no matching group record was found, these functions return
   0 and store NULL in *result.  In case of  error,  an  error  number  is
   returned, and NULL is stored in *result.


   0 or ENOENT or ESRCH or EBADF or EPERM or ...
          The given name or gid was not found.

   EINTR  A signal was caught; see signal(7).

   EIO    I/O error.

   EMFILE The per-process limit on the number of open file descriptors has
          been reached.

   ENFILE The system-wide limit on the total number of open files has been

   ENOMEM Insufficient memory to allocate group structure.

   ERANGE Insufficient buffer space supplied.


          local group database file


   For   an   explanation   of   the  terms  used  in  this  section,  see

   Interface      Attribute      Value                       
   getgrnam()     Thread safety  MT-Unsafe race:grnam locale 
   getgrgid()     Thread safety  MT-Unsafe race:grgid locale 
   getgrnam_r(),  Thread safety  MT-Safe locale              


   POSIX.1-2001, POSIX.1-2008, SVr4, 4.3BSD.


   The formulation given above under "RETURN VALUE" is from  POSIX.1.   It
   does  not  call "not found" an error, hence does not specify what value
   errno might have in this situation.  But that makes  it  impossible  to
   recognize errors.  One might argue that according to POSIX errno should
   be left unchanged if an entry is not  found.   Experiments  on  various
   UNIX-like  systems  show  that  lots  of different values occur in this
   situation: 0, ENOENT, EBADF, ESRCH, EWOULDBLOCK,  EPERM,  and  probably


   endgrent(3),   fgetgrent(3),   getgrent(3),  getpwnam(3),  setgrent(3),


   This page is part of release 4.09 of the Linux  man-pages  project.   A
   description  of  the project, information about reporting bugs, and the
   latest    version    of    this    page,    can     be     found     at

                              2016-03-15                       GETGRNAM(3)

More Linux Commands

lav2yuv(1) - Convert a MJPEG file to raw yuv (Man Page).....
lav2yuv converts an MJPEG video sequence described by a sequence of MJPEG video files and/or edit lists pointing to such files into the simple uncompressed plan

gluTessEndContour(3gl) - delimit a contour description......
gluTessBeginContour and gluTessEndContour delimit the definition of a polygon contour. Within each gluTessBeginContour/gluTessEndContour pair, there can be zero

clnt_pcreateerror(3) - library routines for remote procedure
These routines allow C programs to make procedure calls on other machines across the network. First, the client calls a procedure to send a data packet to the s

ExtUtils::Liblist(3pm) - determine libraries to use and how
This utility takes a list of libraries in the form -llib1 -llib2 -llib3 and returns lines suitable for inclusion in an extension Makefile. Extra library paths m

srftopam(1) convert a SRF image file to Netpbm images.......
This program is part of Netpbm(1) srftopam reads a SRF image file as input and produces a multi-image stream of PAM images as output. This program performs the

DMXForceWindowCreation(3) - force immediate back-end window
When using the lazy window creation optimization, windows are not created on the back-end X servers until they are required. DMXForceWindowCreation() forces the

units(7) - decimal and binary prefixes - Linux manual page
Decimal prefixes The SI system of units uses prefixes that indicate powers of ten. A kilometer is 1000 meter, and a megawatt is 1000000 watt. Below the standard

XGrabButton(3) - grab pointer buttons - Linux manual page...
The XGrabButton function establishes a passive grab. In the future, the pointer is actively grabbed (as for XGrabPointer), the last-pointer-grab time is set to

pad(3ncurses) - create and display curses pads (Man Page)...
The newpad routine creates and returns a pointer to a new pad data structure with the given number of lines, nlines, and columns, ncols. A pad is like a window,

emacs(1) - GNU project Emacs (Commands - Linux man page)....
GNU Emacs is a version of Emacs, written by the author of the original (PDP-10) Emacs, Richard Stallman. The user functionality of GNU Emacs encompasses everyth

Tcl_GetVersion(3) - get the version of the library at runtim
Tcl_GetVersion should be used to query the version number of the Tcl library at runtime. This is useful when using a dynamically loaded Tcl library or when writ

Mail::SpamAssassin::Plugin::Shortcircuit(3pm) - short-circui
This plugin implements simple, test-based shortcircuiting. Shortcircuiting a test will force all other pending rules to be skipped, if that test is hit. In addi

We can't live, work or learn in freedom unless the software we use is free.