#include <sys/types.h> #include <pwd.h> struct passwd *getpwuid(uid_t uid);
getpwuid
returns a pointer to the passwd
structure.
passwd
maps an entry in the user database. uid
is
the user ID for which information is to be returned.
passwd
is defined in <pwd.h>
. It contains the following
members:
pw_name
pw_uid
pw_dir
pw_shell
getpwuid
returns a pointer to the user database entry
if successful. Note that the pointer returned by
getpwuid
may be a static data area that can be rewritten by the
next call to getpwnam
or getpwuid
.
getpwuid
returns a NULL
pointer if unsuccessful.
getpwuid
to obtain a pointer to a passwd
structure:
#include <sys/types.h> #include <pwd.h> #include <stdio.h> . . . struct passwd *p; uid_t uid=0; if ((p = getpwuid(uid)) == NULL) perror("getpwuid() error"); else { printf("getpwuid returned the following name and directory for user ID %d:n", (int) uid); printf("pw_name : %sn", p->pw_name); printf("pw_dir : %dn", p->pw_dir); } . . .
getgrgid
, getpwnam
Copyright (c) 1998 SAS Institute Inc. Cary, NC, USA. All rights reserved.