Chapter Contents |
Previous |
Next |
getpwnam |
Portability: | POSIX.1 conforming, UNIX compatible |
SYNOPSIS | |
DESCRIPTION | |
RETURN VALUE | |
EXAMPLE | |
SEE ALSO |
SYNOPSIS |
#include <sys/types.h> #include <pwd.h> struct passwd *getpwnam(const char *name);
DESCRIPTION |
getpwnam
returns a pointer to the
passwd
structure.
passwd
contains an entry from the user database.
name
is a pointer to the user
name.
passwd
is defined in
<pwd.h>
.
It contains the following members:
pw_name
|
user name |
pw_uid
|
user ID number |
pw_dir
|
initial working directory |
pw_shell
|
initial user program. |
RETURN VALUE |
getpwnam
returns a pointer to a user database entry if successful.
Note that the pointer returned by
getpwnam
may be a static data area that can be rewritten by the next
call to
getpwnam
or
getpwuid
.
getpwnam
returns a
NULL
pointer if unsuccessful.
EXAMPLE |
The following code fragment illustrates
the use of
getpwnam
to
obtain the home directory of the user:
#include <sys/types.h> #include <pwd.h> #include <stdio.h> . . . struct passwd *p; char user[ ] ="YVONNE"; if ((p = getpwnam(user)) == NULL) perror("getpwnam() error"); else { printf("pw_name : %s\n", p-> pw_name); printf("pw_dir : %d\n", p-> pw_dir); } . . .
SEE ALSO |
Chapter Contents |
Previous |
Next |
Top of Page |
Copyright © 2001 by SAS Institute Inc., Cary, NC, USA. All rights reserved.