

#include <sys/types.h> #include <pwd.h> struct passwd *getpwnam(const char *name);
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
pw_uid
pw_dir
pw_shell
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.
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);
}
.
.
.
getgrnam, getpwuid
Copyright (c) 1998 SAS Institute Inc. Cary, NC, USA. All rights reserved.