309 lines
8.4 KiB
HTML
309 lines
8.4 KiB
HTML
|
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<HTML><HEAD><TITLE>Man page of GETPWENT_R</TITLE>
|
|
</HEAD><BODY>
|
|
<H1>GETPWENT_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>
|
|
|
|
getpwent_r, fgetpwent_r - get passwd file entry reentrantly
|
|
<A NAME="lbAC"> </A>
|
|
<H2>SYNOPSIS</H2>
|
|
|
|
<PRE>
|
|
<B>#include <<A HREF="file:///usr/include/pwd.h">pwd.h</A>></B>
|
|
|
|
<B>int getpwent_r(struct passwd *</B><I>pwbuf</I><B>, char *</B><I>buf</I><B>,</B>
|
|
<B> size_t </B><I>buflen</I><B>, struct passwd **</B><I>pwbufp</I><B>);</B>
|
|
|
|
<B>int fgetpwent_r(FILE *</B><I>stream</I><B>, struct passwd *</B><I>pwbuf</I><B>, char *</B><I>buf</I><B>,</B>
|
|
<B> size_t </B><I>buflen</I><B>, struct passwd **</B><I>pwbufp</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>getpwent_r</B>(),
|
|
|
|
<BR> Since glibc 2.19:
|
|
<BR> _DEFAULT_SOURCE
|
|
<BR> Glibc 2.19 and earlier:
|
|
<BR> _BSD_SOURCE || _SVID_SOURCE
|
|
<BR>
|
|
|
|
<B>fgetpwent_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>getpwent_r</B>()
|
|
|
|
and
|
|
<B>fgetpwent_r</B>()
|
|
|
|
are the reentrant versions of
|
|
<B><A HREF="/cgi-bin/man/man2html?3+getpwent">getpwent</A></B>(3)
|
|
|
|
and
|
|
<B><A HREF="/cgi-bin/man/man2html?3+fgetpwent">fgetpwent</A></B>(3).
|
|
|
|
The former reads the next passwd entry from the stream initialized by
|
|
<B><A HREF="/cgi-bin/man/man2html?3+setpwent">setpwent</A></B>(3).
|
|
|
|
The latter reads the next passwd entry from
|
|
<I>stream</I>.
|
|
|
|
<P>
|
|
|
|
The <I>passwd</I> structure is defined in
|
|
<I><<A HREF="file:///usr/include/pwd.h">pwd.h</A>></I>
|
|
|
|
as follows:
|
|
<P>
|
|
|
|
|
|
|
|
struct passwd {
|
|
<BR> char *pw_name; /* username */
|
|
<BR> char *pw_passwd; /* user password */
|
|
<BR> uid_t pw_uid; /* user ID */
|
|
<BR> gid_t pw_gid; /* group ID */
|
|
<BR> char *pw_gecos; /* user information */
|
|
<BR> char *pw_dir; /* home directory */
|
|
<BR> char *pw_shell; /* shell program */
|
|
};
|
|
|
|
|
|
<P>
|
|
|
|
For more information about the fields of this structure, see
|
|
<B><A HREF="/cgi-bin/man/man2html?5+passwd">passwd</A></B>(5).
|
|
|
|
<P>
|
|
|
|
The nonreentrant functions return a pointer to static storage,
|
|
where this static storage contains further pointers to user
|
|
name, password, gecos field, home directory and shell.
|
|
The reentrant functions described here return all of that in
|
|
caller-provided buffers.
|
|
First of all there is the buffer
|
|
<I>pwbuf</I>
|
|
|
|
that can hold a <I>struct passwd</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 passwd</I> read from the stream,
|
|
is stored in the provided buffer
|
|
<I>*pwbuf</I>,
|
|
|
|
and a pointer to this <I>struct passwd</I> is returned in
|
|
<I>*pwbufp</I>.
|
|
|
|
<A NAME="lbAE"> </A>
|
|
<H2>RETURN VALUE</H2>
|
|
|
|
On success, these functions return 0 and
|
|
<I>*pwbufp</I>
|
|
|
|
is a pointer to the <I>struct passwd</I>.
|
|
On error, these functions return an error value and
|
|
<I>*pwbufp</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>getpwent_r</B>()
|
|
|
|
</TD><TD>Thread safety</TD><TD>MT-Unsafe race:pwent locale<BR></TD></TR>
|
|
<TR VALIGN=top><TD>
|
|
<B>fgetpwent_r</B>()
|
|
|
|
</TD><TD>Thread safety</TD><TD>MT-Safe<BR></TD></TR>
|
|
</TABLE>
|
|
|
|
<P>
|
|
In the above table,
|
|
<I>pwent</I>
|
|
|
|
in
|
|
<I>race:pwent</I>
|
|
|
|
signifies that if any of the functions
|
|
<B>setpwent</B>(),
|
|
|
|
<B>getpwent</B>(),
|
|
|
|
<B>endpwent</B>(),
|
|
|
|
or
|
|
<B>getpwent_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 passwd *
|
|
getpwent_r(struct passwd *pwd, char *buf, int buflen);
|
|
|
|
|
|
<P>
|
|
|
|
or, better,
|
|
<P>
|
|
|
|
|
|
|
|
int
|
|
getpwent_r(struct passwd *pwd, char *buf, int buflen,
|
|
<BR> FILE **pw_fp);
|
|
|
|
|
|
<A NAME="lbAI"> </A>
|
|
<H2>NOTES</H2>
|
|
|
|
The function
|
|
<B>getpwent_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/pwd.h">pwd.h</A>>
|
|
#include <<A HREF="file:///usr/include/stdio.h">stdio.h</A>>
|
|
#define BUFLEN 4096
|
|
<P>
|
|
int
|
|
main(void)
|
|
{
|
|
<BR> struct passwd pw, *pwp;
|
|
<BR> char buf[BUFLEN];
|
|
<BR> int i;
|
|
<P>
|
|
<BR> setpwent();
|
|
<BR> while (1) {
|
|
<BR> i = getpwent_r(&pw, buf, BUFLEN, &pwp);
|
|
<BR> if (i)
|
|
<BR> break;
|
|
<BR> printf("%s (%d)\tHOME %s\tSHELL %s\n", pwp->pw_name,
|
|
<BR> pwp->pw_uid, pwp->pw_dir, pwp->pw_shell);
|
|
<BR> }
|
|
<BR> endpwent();
|
|
<BR> exit(EXIT_SUCCESS);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<A NAME="lbAK"> </A>
|
|
<H2>SEE ALSO</H2>
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+fgetpwent">fgetpwent</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+getpw">getpw</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+getpwent">getpwent</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+getpwnam">getpwnam</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+getpwuid">getpwuid</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+putpwent">putpwent</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?5+passwd">passwd</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>
|