getpwent(3) CLIX getpwent(3)
NAME
getpwent, getpwuid, getpwnam, putpwent, setpwent, endpwent, fgetpwent -
Accesses basic user information in password file
LIBRARY
Standard C Library (libc.a)
SYNOPSIS
#include <pwd.h>
struct passwd *getpwent(
void );
struct passwd *getpwuid(
uid_t uid );
struct passwd *getpwnam(
char *name );
int putpwent(
struct passwd *passwd ,
FILE file );
void setpwent(
void );
void endpwent(
void );
struct passwd *fgetpwent(
FILE *file );
PARAMETERS
uid Specifies the ID of the user for which the basic attributes are
to be read.
name Specifies the name of the user for which the basic attributes are
to be read.
passwd Specifies the password structure that contains the user
attributes which are to be written.
file Specifies an open file having a format is like that of the
/etc/passwd file.
DESCRIPTION
2/94 - Intergraph Corporation 1
getpwent(3) CLIX getpwent(3)
The getpwent(), getpwuid(), and getpwnam() functions return a pointer to
an object of type struct passwd containing an entry from the password
file, /etc/passwd. 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;
};
When first called, getpwent() returns a pointer to the first passwd
structure in /etc/passwd. Thereafter, it returns a pointer to the next
passwd structure in the file. This allows successive calls to search the
entire file.
The getpwuid() function searches from the beginning of the /etc/passwd
file until a numerical user ID matching uid is found and returns a pointer
to the structure in which it was found.
The getpwnam() function searches from the beginning of the /etc/passwd
file until a login name matching name is found and returns a pointer to
the structure in which it was found.
The putpwent() function updates user descriptions. Given a pointer to a
passwd structure (possibly created by the getpwent(), getpwuid(), or
getpwnam() functions), the putpwent() function writes a line on the stream
file, which should match the format of the /etc/passwd file.
The setpwent() function effectively rewinds /etc/passwd to allow repeated
searches.
The endpwent() function closes /etc/passwd.
The fgetpwent() function returns a pointer to the next passwd structure in
the stream file. The stream file should match the format of the
/etc/passwd file.
FILES
/etc/passwd System password file.
NOTES
All information generated is stored in a static area and will be
2 Intergraph Corporation - 2/94
getpwent(3) CLIX getpwent(3)
overwritten on subsequent calls to these functions. If this information
is to be saved, it should be copied.
CAUTIONS
The above functions use <stdio.h>, which causes them to increase the size
of programs not otherwise using standard I/O more than might be expected.
RETURN VALUES
The getpwent(), getpwnam(), getpwuid() and fgetpwent() functions return a
pointer to a valid passwd structure if successful. Otherwise, NULL is
returned.
The putpwent() function returns a nonzero value if an error was detected
during its operation. Otherwise, 0 is returned.
RELATED INFORMATION
Commands: ypserv(8)
Functions: getgrent(3), getlogin(3)
Files: pwd.h, passwd(4)
2/94 - Intergraph Corporation 3