308 lines
8.6 KiB
HTML
308 lines
8.6 KiB
HTML
|
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<HTML><HEAD><TITLE>Man page of GETGRENT_R</TITLE>
|
|
</HEAD><BODY>
|
|
<H1>GETGRENT_R</H1>
|
|
Section: Linux Programmer's Manual (3)<BR>Updated: 2017-09-15<BR><A HREF="#index">Index</A>
|
|
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
|
|
|
|
<A NAME="lbAB"> </A>
|
|
<H2>NAME</H2>
|
|
|
|
getgrent_r, fgetgrent_r - get group file entry reentrantly
|
|
<A NAME="lbAC"> </A>
|
|
<H2>SYNOPSIS</H2>
|
|
|
|
<PRE>
|
|
<B>#include <<A HREF="file:///usr/include/grp.h">grp.h</A>></B>
|
|
|
|
<B>int getgrent_r(struct group *</B><I>gbuf</I><B>, char *</B><I>buf</I><B>,</B>
|
|
<B> size_t </B><I>buflen</I><B>, struct group **</B><I>gbufp</I><B>);</B>
|
|
|
|
<B>int fgetgrent_r(FILE *</B><I>stream</I><B>, struct group *</B><I>gbuf</I><B>, char *</B><I>buf</I><B>,</B>
|
|
<B> size_t </B><I>buflen</I><B>, struct group **</B><I>gbufp</I><B>);</B>
|
|
</PRE>
|
|
|
|
<P>
|
|
|
|
|
|
Feature Test Macro Requirements for glibc (see
|
|
<B><A HREF="/cgi-bin/man/man2html?7+feature_test_macros">feature_test_macros</A></B>(7)):
|
|
|
|
|
|
<P>
|
|
|
|
<B>getgrent_r</B>():
|
|
|
|
_GNU_SOURCE
|
|
|
|
<BR>
|
|
|
|
<B>fgetgrent_r</B>():
|
|
|
|
<BR> Since glibc 2.19:
|
|
<BR> _DEFAULT_SOURCE
|
|
<BR> Glibc 2.19 and earlier:
|
|
<BR> _SVID_SOURCE
|
|
<A NAME="lbAD"> </A>
|
|
<H2>DESCRIPTION</H2>
|
|
|
|
The functions
|
|
<B>getgrent_r</B>()
|
|
|
|
and
|
|
<B>fgetgrent_r</B>()
|
|
|
|
are the reentrant versions of
|
|
<B><A HREF="/cgi-bin/man/man2html?3+getgrent">getgrent</A></B>(3)
|
|
|
|
and
|
|
<B><A HREF="/cgi-bin/man/man2html?3+fgetgrent">fgetgrent</A></B>(3).
|
|
|
|
The former reads the next group entry from the stream initialized by
|
|
<B><A HREF="/cgi-bin/man/man2html?3+setgrent">setgrent</A></B>(3).
|
|
|
|
The latter reads the next group entry from
|
|
<I>stream</I>.
|
|
|
|
<P>
|
|
|
|
The <I>group</I> structure is defined in
|
|
<I><<A HREF="file:///usr/include/grp.h">grp.h</A>></I>
|
|
|
|
as follows:
|
|
<P>
|
|
|
|
|
|
|
|
struct group {
|
|
<BR> char *gr_name; /* group name */
|
|
<BR> char *gr_passwd; /* group password */
|
|
<BR> gid_t gr_gid; /* group ID */
|
|
<BR> char **gr_mem; /* NULL-terminated array of pointers
|
|
<BR> to names of group members */
|
|
};
|
|
|
|
|
|
<P>
|
|
|
|
For more information about the fields of this structure, see
|
|
<B><A HREF="/cgi-bin/man/man2html?5+group">group</A></B>(5).
|
|
|
|
<P>
|
|
|
|
The nonreentrant functions return a pointer to static storage,
|
|
where this static storage contains further pointers to group
|
|
name, password and members.
|
|
The reentrant functions described here return all of that in
|
|
caller-provided buffers.
|
|
First of all there is the buffer
|
|
<I>gbuf</I>
|
|
|
|
that can hold a <I>struct group</I>.
|
|
And next the buffer
|
|
<I>buf</I>
|
|
|
|
of size
|
|
<I>buflen</I>
|
|
|
|
that can hold additional strings.
|
|
The result of these functions, the <I>struct group</I> read from the stream,
|
|
is stored in the provided buffer
|
|
<I>*gbuf</I>,
|
|
|
|
and a pointer to this <I>struct group</I> is returned in
|
|
<I>*gbufp</I>.
|
|
|
|
<A NAME="lbAE"> </A>
|
|
<H2>RETURN VALUE</H2>
|
|
|
|
On success, these functions return 0 and
|
|
<I>*gbufp</I>
|
|
|
|
is a pointer to the <I>struct group</I>.
|
|
On error, these functions return an error value and
|
|
<I>*gbufp</I>
|
|
|
|
is NULL.
|
|
<A NAME="lbAF"> </A>
|
|
<H2>ERRORS</H2>
|
|
|
|
<DL COMPACT>
|
|
<DT id="1"><B>ENOENT</B>
|
|
|
|
<DD>
|
|
No more entries.
|
|
<DT id="2"><B>ERANGE</B>
|
|
|
|
<DD>
|
|
Insufficient buffer space supplied.
|
|
Try again with larger buffer.
|
|
</DL>
|
|
<A NAME="lbAG"> </A>
|
|
<H2>ATTRIBUTES</H2>
|
|
|
|
For an explanation of the terms used in this section, see
|
|
<B><A HREF="/cgi-bin/man/man2html?7+attributes">attributes</A></B>(7).
|
|
|
|
<TABLE BORDER>
|
|
<TR VALIGN=top><TD><B>Interface</B></TD><TD><B>Attribute</B></TD><TD><B>Value</B><BR></TD></TR>
|
|
<TR VALIGN=top><TD>
|
|
<B>getgrent_r</B>()
|
|
|
|
</TD><TD>Thread safety</TD><TD>MT-Unsafe race:grent locale<BR></TD></TR>
|
|
<TR VALIGN=top><TD>
|
|
<B>fgetgrent_r</B>()
|
|
|
|
</TD><TD>Thread safety</TD><TD>MT-Safe<BR></TD></TR>
|
|
</TABLE>
|
|
|
|
<P>
|
|
In the above table,
|
|
<I>grent</I>
|
|
|
|
in
|
|
<I>race:grent</I>
|
|
|
|
signifies that if any of the functions
|
|
<B>setgrent</B>(),
|
|
|
|
<B>getgrent</B>(),
|
|
|
|
<B>endgrent</B>(),
|
|
|
|
or
|
|
<B>getgrent_r</B>()
|
|
|
|
are used in parallel in different threads of a program,
|
|
then data races could occur.
|
|
<A NAME="lbAH"> </A>
|
|
<H2>CONFORMING TO</H2>
|
|
|
|
These functions are GNU extensions, done in a style resembling
|
|
the POSIX version of functions like
|
|
<B><A HREF="/cgi-bin/man/man2html?3+getpwnam_r">getpwnam_r</A></B>(3).
|
|
|
|
Other systems use the prototype
|
|
<P>
|
|
|
|
|
|
|
|
struct group *getgrent_r(struct group *grp, char *buf,
|
|
<BR> int buflen);
|
|
|
|
|
|
<P>
|
|
|
|
or, better,
|
|
<P>
|
|
|
|
|
|
|
|
int getgrent_r(struct group *grp, char *buf, int buflen,
|
|
<BR> FILE **gr_fp);
|
|
|
|
|
|
<A NAME="lbAI"> </A>
|
|
<H2>NOTES</H2>
|
|
|
|
The function
|
|
<B>getgrent_r</B>()
|
|
|
|
is not really reentrant since it shares the reading position
|
|
in the stream with all other threads.
|
|
<A NAME="lbAJ"> </A>
|
|
<H2>EXAMPLE</H2>
|
|
|
|
|
|
#define _GNU_SOURCE
|
|
#include <<A HREF="file:///usr/include/grp.h">grp.h</A>>
|
|
#include <<A HREF="file:///usr/include/stdio.h">stdio.h</A>>
|
|
#include <<A HREF="file:///usr/include/stdlib.h">stdlib.h</A>>
|
|
#define BUFLEN 4096
|
|
<P>
|
|
int
|
|
main(void)
|
|
{
|
|
<BR> struct group grp, *grpp;
|
|
<BR> char buf[BUFLEN];
|
|
<BR> int i;
|
|
<P>
|
|
<BR> setgrent();
|
|
<BR> while (1) {
|
|
<BR> i = getgrent_r(&grp, buf, BUFLEN, &grpp);
|
|
<BR> if (i)
|
|
<BR> break;
|
|
<BR> printf("%s (%d):", grpp->gr_name, grpp->gr_gid);
|
|
<BR> for (i = 0; ; i++) {
|
|
<BR> if (grpp->gr_mem[i] == NULL)
|
|
<BR> break;
|
|
<BR> printf(" %s", grpp->gr_mem[i]);
|
|
<BR> }
|
|
<BR> printf("\n");
|
|
<BR> }
|
|
<BR> endgrent();
|
|
<BR> exit(EXIT_SUCCESS);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<A NAME="lbAK"> </A>
|
|
<H2>SEE ALSO</H2>
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+fgetgrent">fgetgrent</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+getgrent">getgrent</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+getgrgid">getgrgid</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+getgrnam">getgrnam</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+putgrent">putgrent</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?5+group">group</A></B>(5)
|
|
|
|
<A NAME="lbAL"> </A>
|
|
<H2>COLOPHON</H2>
|
|
|
|
This page is part of release 5.05 of the Linux
|
|
<I>man-pages</I>
|
|
|
|
project.
|
|
A description of the project,
|
|
information about reporting bugs,
|
|
and the latest version of this page,
|
|
can be found at
|
|
<A HREF="https://www.kernel.org/doc/man-pages/.">https://www.kernel.org/doc/man-pages/.</A>
|
|
<P>
|
|
|
|
<HR>
|
|
<A NAME="index"> </A><H2>Index</H2>
|
|
<DL>
|
|
<DT id="3"><A HREF="#lbAB">NAME</A><DD>
|
|
<DT id="4"><A HREF="#lbAC">SYNOPSIS</A><DD>
|
|
<DT id="5"><A HREF="#lbAD">DESCRIPTION</A><DD>
|
|
<DT id="6"><A HREF="#lbAE">RETURN VALUE</A><DD>
|
|
<DT id="7"><A HREF="#lbAF">ERRORS</A><DD>
|
|
<DT id="8"><A HREF="#lbAG">ATTRIBUTES</A><DD>
|
|
<DT id="9"><A HREF="#lbAH">CONFORMING TO</A><DD>
|
|
<DT id="10"><A HREF="#lbAI">NOTES</A><DD>
|
|
<DT id="11"><A HREF="#lbAJ">EXAMPLE</A><DD>
|
|
<DT id="12"><A HREF="#lbAK">SEE ALSO</A><DD>
|
|
<DT id="13"><A HREF="#lbAL">COLOPHON</A><DD>
|
|
</DL>
|
|
<HR>
|
|
This document was created by
|
|
<A HREF="/cgi-bin/man/man2html">man2html</A>,
|
|
using the manual pages.<BR>
|
|
Time: 00:05:44 GMT, March 31, 2021
|
|
</BODY>
|
|
</HTML>
|