-->

Previous | Table of Contents | Next

Page 943

FILES

/etc/passwd Password database file

SEE ALSO

fgetpwent(3), getpwent(3), setpwent(3), endpwent(3), getpwnam(3), getpwuid(3), putpwent(3), passwd(5)

GNU, 27 May 1996

getpwent, setpwent, endpwent

getpwent, setpwent, endpwent—get password file entry

SYNOPSIS


#include <pwd.h>

#include <sys/types.h>

struct passwd *getpwent(void);

void setpwent(void);

void endpwent(void);

DESCRIPTION

The getpwent() function returns a pointer to a structure containing the broken-out fields of a line from /etc/passwd. The first time it is called it returns the first entry; thereafter, it returns successive entries.

The setpwent() function rewinds the file pointer to the beginning of the /etc/passwd file.

The endpwent() function closes the /etc/passwd file.

The passwd structure is defined in <pwd.h> as follows:


struct passwd {

        char     *pw_name;     /*username*/

        char     *pw_passwd;   /* user password */

        uid_t    pw_uid;       /* user id */

        gid_t    pw_gid;       /* group id */

        char     *pw_gecos;    /* real name */

        char     *pw_dir;      /* home directory */

        char     *pw_shell;    /* shell program */

};

RETURN VALUE

The getpwent()function returns the passwd structure, or NULL if there are no more entries or an error occurs.

ERRORS

ENOMEM Insufficient memory to allocate passwd structure.

FILES

/etc/passwd Password database file

CONFORMS TO

SVID 3, BSD 4.3

SEE ALSO

fgetpwent(3), getpwnam(3), getpwuid(3), getpw(3), putpwent(3), passwd(5).

GNU, 27 May 1996

Page 944

getpwnam, getpwuid

getpwnam, getpwuid—Get password file entry

SYNOPSIS


#include <pwd.h>

#include <sys/types.h>

struct passwd *getpwnam(const char * name);

struct passwd *getpwuid(uid_t uid);

DESCRIPTION

The getpwnam() function returns a pointer to a structure containing the broken out fields of a line from /etc/passwd for the entry that matches the username name.

The getpwuid() function returns a pointer to a structure containing the broken-out fields of a line from /etc/passwd for the entry that matches the user UID uid.

The passwd structure is defined in <pwd.h> as follows:


struct passwd {

        char     *pw_name;     /*username*/

        char     *pw_passwd;   /* user password */

        uid_t    pw_uid;       /* user id */

        gid_t    pw_gid;       /* group id */

        char     *pw_gecos;    /* real name */

        char     *pw_dir;      /* home directory */

        char     *pw_shell;    /* shell program */

};

RETURN VALUE

The getpwnam()and getpwuid() functions return the passwd structure, or NULL if the matching entry is not found or an error occurs.

ERRORS

ENOMEM Insufficient memory to allocate passwd structure.

FILES

/etc/passwd Password database file

CONFORMS TO

SVID 3, POSIX, BSD 4.3

SEE ALSO

fgetpwent(3), getpwent(3), setpwent(3), endpwent(3), getpw(3), putpwent(3), passwd(5)

GNU, 27 May 1996

fgetc, fgets, getc, getchar, gets, ungetc

fgetc, fgets, getc, getchar, gets, ungetc—Input of characters and strings

SYNOPSIS


#include <stdio.h>

int fgetc(FILE *stream);

char *fgets(char *s,int size, FILE *stream);

Page 945


int getc(FILE *stream);

int getchar(void);

char *gets(char *s);

int ungetc(int c, FILE *stream);

DESCRIPTION

fgetc() reads the next character from stream and returns it as an unsigned char cast to an int, or EOF on end of file or error.

getc() is equivalent to fgetc() except that it can be implemented as a macro that evaluates stream more than once.

getchar() is equivalent to getc(stdin).

gets()reads a line from stdin into the buffer pointed to by s until either a terminating newline or EOF, which it replaces with \0. No check for buffer overrun is performed (see the following "Bus" section).

fgets() reads in at most one less than n characters from stream and stores them into the buffer pointed to by s. Reading stops after an EOF or a newline. If a newline is read, it is stored into the buffer. \0 is stored after the last character in the buffer.

ungetc() pushes c back to stream, cast to unsigned char, where it is available for subsequent read operations. Pushed-back characters will be returned in reverse order; only one pushback is guaranteed.

Calls to the functions described here can be mixed with each other and with calls to other input functions from the stdio library for the same input stream.

RETURN VALUES

fgetc(), getc(), and getchar() return the character read as an unsigned char cast to an int, or EOF on end of file or error.

gets() and fgets() return s on success, and NULL on error or when end of file occurs while no characters have been read.

ungetc() returns c on success, or EOF on error.

CONFORMS TO

ANSI—C, POSIX.1

BUGS

Because it is impossible to tell without knowing the data in advance how many characters gets() will read, and because gets() will continue to store characters past the end of the buffer, it is extremely dangerous to use. It has been used to break computer security. Use fgets() instead.

It is not advisable to mix calls to input functions from the stdio library with low-level calls to read() for the file descriptor associated with the input stream; the results will be undefined and very probably not what you want.

SEE ALSO

read(2), write(2), fopen(3), fread(3), scanf(3), puts(3), fseek(3), ferror(3)

GNU, 4 April 1993

getservent, getservbyname, getservbyport, setservent,
endservent

getservent, getservbyname, getservbyport, setservent, endservent—Get service entry

SYNOPSIS


#include <netdb.h>

struct servent *getservent(void);

struct servent *getservbyname(const char *name, const char *proto);

struct servent *getservbyport(int port, const char *proto);

Previous | Table of Contents | Next