[Previous]
[Contents]
[Next]

getlogin()

get the user's login name

Synopsis:

#include <unistd.h>
char *getlogin( void );

Description:

The getlogin() function generates a string that contains the name associated with the login activity of the controlling terminal.

Returns:

A pointer to the user's login name. The same user ID may be shared by several login names. Therefore, to ensure that the correct user database entry is found, the getlogin() function should be used in conjunction with the getpwnam() function.

If getlogin() returns a non-NULL pointer, that pointer is to the name of the logged-in user, even if there are several login names with the same user ID.

Examples:

/* Print the user's login id. */
#include <stdio.h>
#include <unistd.h>

void main()
  {
    char *s;

    if( ( s = getlogin() ) == NULL ) {
       printf( "cannot find login name\n" );
    } else {
       printf( "login name is %s\n", s );
    }
  }

Classification:

POSIX 1003.1

Safety:
Interrupt handler No
Signal handler Yes, but modifies errno
Thread No

See also:

cuserid(), getpwuid(), getpwnam(), getuid()


[Previous]
[Contents]
[Next]