GETPWENT(S) UNIX System V GETPWENT(S)
Name
getpwent, getpwuid, getpwnam, setpwent, endpwent, fgetpwent
- get password file entry
Syntax
#include <pwd.h>
struct passwd *getpwent ( )
struct passwd *getpwuid (uid)
int uid;
struct passwd *getpwnam (name)
char *name;
void setpwent ( )
void endpwent ( )
struct passwd *fgetpwent (f)
FILE *f;
Description
The getpwent, getpwuid, and getpwnam functions each returns
a pointer to an object with the following structure
containing the broken-out fields of a line in the
/etc/passwd file. Each line in the file contains a
``passwd'' structure, declared in the <pwd.h> header file:
struct passwd {
char *pw_name;
char *pw_passwd;
int pw_uid;
int pw_gid;
char *pw_age;
char *pw_comment;
char *pw_gecos;
char *pw_dir;
char *pw_shell;
};
This structure is declared in <pwd.h> so it is not necessary
to redeclare it.
The fields have meanings described in passwd(F).
The getpwent function when first called, returns a pointer
to the first passwd structure in the file; thereafter, it
returns a pointer to the next passwd structure in the file;
so successive calls can be used to search the entire file.
getpwuid searches from the beginning of the file until a
numerical user ID matching uid is found and returns a
pointer to the particular structure in which it was found.
getpwnam searches from the beginning of the file until a
login name matching name is found, and returns a pointer to
the particular structure in which it was found. If an end-
of-file or an error is encountered on reading, these
functions return a NULL pointer.
A call to setpwent has the effect of rewinding the password
file to allow repeated searches. endpwent may be called to
close the password file when processing is complete.
fgetpwent returns a pointer to the next passwd structure in
the stream f, which matches the format of /etc/passwd.
Files
/etc/passwd
See Also
getlogin(S), getgrent(S), passwd(F)
Diagnostics
A NULL pointer is returned on EOF or error.
Warning
The above routines use <stdio.h>, which causes them to
increase the size of programs, not otherwise using standard
I/O, more than might be expected.
Note
All information is contained in a static area, so it must be
copied if it is to be saved.
Standards Conformance
endpwent, getpwent and setpwent are conformant with:
AT&T SVID Issue 2, Select Code 307-127;
and The X/Open Portability Guide II of January 1987.
getpwnam and getpwuid are conformant with:
AT&T SVID Issue 2, Select Code 307-127;
The X/Open Portability Guide II of January 1987;
IEEE POSIX Std 1003.1-1988 with C Standard Language-
Dependent System Support;
and NIST FIPS 151-1.
(printed 6/20/89)