Gets a user's login name.
Thread-Safe C Library (libc_r.a)
int getlogin_r (Name, Length)
char * Name;
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.
|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.|
|0||Indicates that the subroutine was successful.|
|-1||Indicates that the subroutine was not successful.|
If the getlogin_r
subroutine does not succeed, it returns one of the following error
|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.|
This subroutine is part of Base Operating System (BOS) Runtime. Programs using this subroutine must link to the libpthreads.a library.
|/etc/utmp||Contains a record of users logged into the system.|
The getgrent_r, getgrgid_r, getgrnam_r, setgrent_r, or endgrent_r (getgrent, getgrgid, getgrnam, setgrent, or endgrent Subroutine) subroutine, getlogin (getlogin Subroutine) subroutine, getpwent_r, getpwnam_r, putpwent_r, getpwuid_r, setpwent_r, or endpwent_r (getpwent, getpwuid, getpwnam, putpwent, setpwent, or endpwent Subroutine) subroutine.
List of Security and Auditing Subroutines, List of Multithread Subroutines, and Subroutines Overview in AIX 5L Version 5.1 General Programming Concepts: Writing and Debugging Programs.