[ Bottom of Page | Previous Page | Next Page | Contents | Index | Library Home | Legal | Search ]

Technical Reference: Base Operating System and Extensions, Volume 1

getlogin Subroutine

Purpose

Gets a user's login name.

Library

Standard C Library (libc.a)

Syntax

include <sys/types.h>
include <unistd.h>
include <limits.h>

char *getlogin (void)

Description

Attention: Do not use the getlogin subroutine in a multithreaded environment. To access the thread-safe version of this subroutines, see the getlogin_r (getlogin_r Subroutine) subroutine.
Attention: The getlogin subroutine returns a pointer to an area that may be overwritten by successive calls.

The getlogin subroutine returns a pointer to the login name in the /etc/utmp file. You can use the getlogin subroutine with the getpwnam (getpwent, getpwuid, getpwnam, putpwent, setpwent, or endpwent Subroutine) subroutine to locate the correct password file entry when the same user ID is shared by several login names.

If the getlogin subroutine cannot find the login name in the /etc/utmp file, it returns the process LOGNAME environment variable. If the getlogin subroutine is called within a process that is not attached to a terminal, it returns the value of the LOGNAME environment variable. If the LOGNAME environment variable does not exist, a null pointer is returned.

Return Values

The return value can point to static data whose content is overwritten by each call. If the login name is not found, the getlogin subroutine returns a null pointer.

Error Codes

If the getlogin function is unsuccessful, it returns one or more of the following error codes:

EMFILE Indicates that the OPEN_MAX file descriptors are currently open in the calling process.
ENFILE Indicates that the maximum allowable number of files is currently open in the system.
ENXIO Indicates that the calling process has no controlling terminal.

Files

/etc/utmp Contains a record of users logged into the system.

Related Information

The getgrent, getgrgid, getgrnam, putgrent, setgrent, or endgrent (getgrent, getgrgid, getgrnam, setgrent, or endgrent Subroutine) subroutine, getlogin_r (getlogin_r Subroutine) subroutine, getpwent, getpwuid, setpwent, or endpwent (getpwent, getpwuid, getpwnam, putpwent, setpwent, or endpwent Subroutine) subroutine, getpwnam (getpwent, getpwuid, getpwnam, putpwent, setpwent, or endpwent Subroutine) subroutine.

List of Security and Auditing Subroutines, Subroutines Overview in AIX 5L Version 5.2 General Programming Concepts: Writing and Debugging Programs.

[ Top of Page | Previous Page | Next Page | Contents | Index | Library Home | Legal | Search ]