1GETGRENT(3)                Linux Programmer's Manual               GETGRENT(3)
2
3
4

NAME

6       getgrent, setgrent, endgrent - get group file entry
7

SYNOPSIS

9       #include <sys/types.h>
10       #include <grp.h>
11
12       struct group *getgrent(void);
13
14       void setgrent(void);
15       void endgrent(void);
16
17   Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
18
19       setgrent():
20           _XOPEN_SOURCE >= 500
21               || /* Glibc since 2.19: */ _DEFAULT_SOURCE
22               || /* Glibc <= 2.19: */ _BSD_SOURCE || _SVID_SOURCE
23
24       getgrent(), endgrent():
25           Since glibc 2.22:
26               _XOPEN_SOURCE >= 500 || _DEFAULT_SOURCE
27           Glibc 2.21 and earlier
28               _XOPEN_SOURCE >= 500
29                   || /* Since glibc 2.12: */ _POSIX_C_SOURCE >= 200809L
30                   || /* Glibc <= 2.19: */ _BSD_SOURCE || _SVID_SOURCE
31

DESCRIPTION

33       The getgrent() function returns a pointer to a structure containing the
34       broken-out fields of a record in the group database  (e.g.,  the  local
35       group  file  /etc/group,  NIS, and LDAP).  The first time getgrent() is
36       called, it returns the first entry; thereafter, it  returns  successive
37       entries.
38
39       The setgrent() function rewinds to the beginning of the group database,
40       to allow repeated scans.
41
42       The endgrent() function is used to close the group database  after  all
43       processing has been performed.
44
45       The group structure is defined in <grp.h> as follows:
46
47           struct group {
48               char   *gr_name;        /* group name */
49               char   *gr_passwd;      /* group password */
50               gid_t   gr_gid;         /* group ID */
51               char  **gr_mem;         /* NULL-terminated array of pointers
52                                          to names of group members */
53           };
54
55       For more information about the fields of this structure, see group(5).
56

RETURN VALUE

58       The getgrent() function returns a pointer to a group structure, or NULL
59       if there are no more entries or an error occurs.
60
61       Upon error, errno may be set.  If one wants to check  errno  after  the
62       call, it should be set to zero before the call.
63
64       The  return value may point to a static area, and may be overwritten by
65       subsequent calls to getgrent(), getgrgid(3), or getgrnam(3).   (Do  not
66       pass the returned pointer to free(3).)
67

ERRORS

69       EAGAIN The  service  was temporarily unavailable; try again later.  For
70              NSS backends in glibc this indicates a temporary  error  talking
71              to the backend.  The error may correct itself, retrying later is
72              suggested.
73
74       EINTR  A signal was caught; see signal(7).
75
76       EIO    I/O error.
77
78       EMFILE The per-process limit on the number of open file descriptors has
79              been reached.
80
81       ENFILE The system-wide limit on the total number of open files has been
82              reached.
83
84       ENOENT A necessary input file cannot be found.   For  NSS  backends  in
85              glibc this indicates the backend is not correctly configured.
86
87       ENOMEM Insufficient memory to allocate group structure.
88
89       ERANGE Insufficient buffer space supplied.
90

FILES

92       /etc/group
93              local group database file
94

ATTRIBUTES

96       For  an  explanation  of  the  terms  used  in  this  section,  see at‐
97       tributes(7).
98
99       ┌────────────┬───────────────┬─────────────────────────────────────────┐
100Interface   Attribute     Value                                   
101       ├────────────┼───────────────┼─────────────────────────────────────────┤
102getgrent()  │ Thread safety │ MT-Unsafe race:grent race:grentbuf      │
103       │            │               │ locale                                  │
104       ├────────────┼───────────────┼─────────────────────────────────────────┤
105setgrent(), │ Thread safety │ MT-Unsafe race:grent locale             │
106endgrent()  │               │                                         │
107       └────────────┴───────────────┴─────────────────────────────────────────┘
108
109       In the above table, grent in race:grent signifies that if  any  of  the
110       functions setgrent(), getgrent(), or endgrent() are used in parallel in
111       different threads of a program, then data races could occur.
112

CONFORMING TO

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

SEE ALSO

117       fgetgrent(3), getgrent_r(3), getgrgid(3), getgrnam(3), getgrouplist(3),
118       putgrent(3), group(5)
119

COLOPHON

121       This  page  is  part of release 5.12 of the Linux man-pages project.  A
122       description of the project, information about reporting bugs,  and  the
123       latest     version     of     this    page,    can    be    found    at
124       https://www.kernel.org/doc/man-pages/.
125
126
127
128                                  2021-03-22                       GETGRENT(3)
Impressum