DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH
 

getlogin(S)


getlogin, getlogin_r -- get login name

Syntax

cc . . . -lc

char *getlogin(void);

char *getlogin_r(char *name, size_t namelen);

Description

The getlogin(S) routine returns a pointer to the login name as found in the file /etc/utmp. If getlogin() is called within a process that is not attached to a terminal, it returns a NULL pointer.

getlogin() may be used in conjunction with the getpwnam routine to locate the correct password file entry when the same user ID is shared by several login names.

The correct procedure for determining the login name is to call the cuserid(S) or the getlogin() routine. If both fail, one should call the getpwuid routine.

getlogin_r(S) puts the name associated by the login activity with the control terminal of the current process in the character string pointed to by name. As the same user ID may be shared by several login names, use getlogin_r() with getpwnam(S)(see getpwent(S)) to ensure that the correct user database entry is found. If successful, getlogin_r() returns name which points to the name the user logged in under, even if there are several login names with the same user ID.

Return value

Upon successful completion, the getlogin() routine returns a pointer to the login name. If the login name is not found or if an error while accessing the /etc/utmp file occurs, getlogin() returns the NULL pointer.

getlogin_r() returns a pointer to a string containing the user's login name, or NULL if the user's login name cannot be found. This is a pointer to the string passed in by name. If an error is detected, getlogin_r() returns NULL and sets errno.

Diagnostics

getlogin() and getlogin_r() return a null pointer if the login name is not found.

getlogin_r() returns NULL and sets errno to ERANGE when namelen is smaller than the length of the string.

The getlogin() function may fail if:


[EMFILE]
{OPEN_MAX} file descriptors currently open in the calling process.

[ENFILE]
The maximum allowable number of files is currently open in the system.

[ENXIO]
The calling process has no controlling terminal.

Note

The return value points to static data whose content is overwritten by each call. Therefore, the information should be copied if it needs to be saved or used later.

Files

/etc/utmp

See also

cuserid(S), getgrent(S), getpwent(S), utmp(F)

Standards conformance

getlogin conforms with:

X/Open Portability Guide, Issue 3, 1989 ;
IEEE POSIX Std 1003.1-1990 System Application Program Interface (API) [C Language] (ISO/IEC 9945-1) ;
and NIST FIPS 151-1 .


© 2003 Caldera International, Inc. All rights reserved.
SCO OpenServer Release 5.0.7 -- 11 February 2003