[ Previous | Next | Contents | Glossary | Home | Search ]
AIX Version 4.3 Base Operating System and Extensions Technical Reference, Volume 1

getlogin_r Subroutine

Purpose

Gets a user's login name.

Library

Thread-Safe C Library (libc_r.a)

Syntax

int getlogin_r (Name, Length)
char *Name;
size_t Length;

Description

The getlogin_r subroutine gets a user's login name from the /etc/utmp file and places it in the Name parameter. Only the number of bytes specified by the Length parameter (including the ending null value) are placed in the Name parameter.

Applications that call the getlogin_r subroutine must allocate memory for the login name before calling the subroutine. The name buffer must be the length of the Name parameter plus an ending null value.

If the getlogin_r subroutine cannot find the login name in the utmp file or the process is not attached to a terminal, it places the LOGNAME environment variable in the name buffer. If the LOGNAME environment variable does not exist, the Name parameter is set to null and the getlogin_r subroutine returns a -1.

Parameters

Name Specifies a buffer for the login name. This buffer should be the length of the Length parameter plus an ending null value.
Length Specifies the total length in bytes of the Name parameter. No more bytes than the number specified by the Length parameter are placed in the Name parameter, including the ending null value.

Return Values

0 Indicates that the subroutine was successful.
-1 Indicates that the subroutine was not successful.

Error Codes

If the getlogin_r subroutine does not succeed, it returns one 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 are currently open in the system.
ENXIO Indicates that the calling process has no controlling terminal.

Implementation Specifics

This subroutine is part of Base Operating System (BOS) Runtime. Programs using this subroutine must link to the libpthreads.a library.

File

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

Related Information

The getgrent_r, getgrgid_r, getgrnam_r, setgrent_r, or endgrent_r subroutine, getlogin subroutine, getpwent_r, getpwnam_r, putpwent_r, getpwuid_r, setpwent_r, or endpwent_r subroutine.

List of Security and Auditing Subroutines, List of Multithread Subroutines, and Subroutines Overview in AIX Version 4.3 General Programming Concepts: Writing and Debugging Programs.


[ Previous | Next | Contents | Glossary | Home | Search ]