getpwuid -- Access User Database by User ID

SYNOPSIS

 #include <sys/types.h>
 #include <pwd.h>

 struct passwd *getpwuid(uid_t uid);
 

DESCRIPTION

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
user name
pw_uid
user ID number
pw_dir
initial working directory
pw_shell
initial user program.

RETURN VALUE

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.

EXAMPLE

The following code fragment illustrates the use of 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);
 }
 .
 .
 .

 

RELATED FUNCTIONS

getgrgid, getpwnam


Copyright (c) 1998 SAS Institute Inc. Cary, NC, USA. All rights reserved.