Standards / Extensions | C or C++ | Dependencies |
---|---|---|
POSIX.1 |
both |
#define _POSIX_SOURCE
#include <pwd.h>
struct passwd *getpwnam(const char *name);
If successful, getpwnam() returns a pointer to a passwd structure containing an entry from the user database with the specified name. Return values may point to the static data that is overwritten on each call.
⁄* CELEBG16
This example provides information for the user data
base, MEGA.
*⁄
#define _POSIX_SOURCE
#include <sys⁄types.h>
#include <pwd.h>
main() {
struct passwd *p;
char user[]="MEGA";
if ((p = getpwnam(user)) == NULL)
perror("getpwnam() error");
else {
printf("getpwnam() returned the following info for user %s:\n",
user);
printf(" pw_name : %s\n", p->pw_name);
printf(" pw_uid : %d\n", (int) p->pw_uid);
printf(" pw_gid : %d\n", (int) p->pw_gid);
printf(" pw_dir : %s\n", p->pw_dir);
printf(" pw_shell : %s\n", p->pw_shell);
}
}
pw_name : MEGA
pw_uid : 0
pw_gid : 512
pw_dir : /u/mega
pw_shell : /bin/sh