[Go to CFHT Home Page] Man Pages
Back to Software Index  BORDER=0Manpage Top Level
    getlogin(3C) manual page Table of Contents

Name

getlogin, getlogin_r - get login name

Synopsis

#include <stdlib.h>

char *getlogin(void);

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

Posix

cc [ flag... ] file ... -D_POSIX_PTHREAD_SEMANTICS [ library... ]

int getlogin_r(char *name, size_t namesize);

MT-Level

See the NOTES section of this page.

Description

getlogin() returns a pointer to the login name as found in /var/adm/utmp. It may be used in conjunction with getpwnam() to locate the correct password file entry when the same user id is shared by several login names.

If getlogin() is called within a process that is not attached to a terminal, it returns a null pointer. The correct procedure for determining the login name is to call cuserid(), or to call getlogin() and if it fails to call getpwuid().

getlogin_r() has the same functionality as getlogin() except that the caller must supply a buffer name with length namelen to store the result. The name buffer must be at least LOGNAME_MAX bytes in size (defined in <limits.h>). The POSIX version of getlogin_r() takes a namesize parameter of type size_t.

Return Values

Returns a null pointer if the login name is not found.

Errors

getlogin_r() will fail if the following is true:

ERANGE
The size of the buffer is smaller than the result to be returned.

The POSIX getlogin_r() returns zero if successful, or the error number upon failure.

Files

/var/adm/utmp

See Also

cuserid(3S) , getgrnam(3C) , getpwnam(3C) , utmp(4)

Notes

When compiling multithread programs, see Intro(3) , Notes On Multithread Applications.

The return values point to static data whose content is overwritten by each call.

getlogin() is unsafe in multi-thread applications. getlogin_r() should be used instead.

Solaris 2.4 and earlier releases provided a getlogin_r() as specified in POSIX.1c Draft 6. The final POSIX.1c standard changed the interface as described above. Support for the Draft 6 interface is provided for compatibility only and may not be supported in future releases. New applications and libraries should use the POSIX standard interface.


Table of Contents