[Previous]
[Contents]
[Next]

getpwuid()

get information about the user with a given ID

Synopsis:

#include <sys/types.h>
#include <pwd.h>
struct passwd *getpwuid( uid_t uid );

Description:

The getpwuid() function allows a process to gain more knowledge about user uid. This function uses a static buffer that's overwritten by each call.

Returns:

A pointer to an object of type struct passwd() containing an entry from the group database with a matching uid. Upon error or failure to find a entry with a matching uid, a NULL pointer is returned.

Examples:

/*
 * print password info on the current user.
 */
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/types.h>
#include <pwd.h>

void main()
  {
    struct passwd *pw;

    if( ( pw = getpwuid( getuid() ) ) == NULL ) {
       fprintf( stderr,
          "getpwuid: no password entry\n" );
       exit( EXIT_FAILURE );
    }
    printf( "login name  %s\n", pw->pw_name );
    printf( "user ID     %d\n", pw->pw_uid );
    printf( "group ID    %d\n", pw->pw_gid );
    printf( "home dir    %s\n", pw->pw_dir );
    printf( "login shell %s\n", pw->pw_shell );
    exit( EXIT_SUCCESS );
  }

Classification:

POSIX 1003.1

Safety:
Interrupt handler No
Signal handler No
Thread No

See also:

cuserid(), getlogin(), getpwent(), getpwnam()


[Previous]
[Contents]
[Next]