getlogin(3C)


getlogin, getlogin_r -- get login name

Synopsis

   #include <stdlib.h>
   char *getlogin(void);
   

#include <unistd.h> int getlogin_r(char *name, size_t namelen);

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 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[see getpwent(3C)] 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.

Files

/var/adm/utmp

Return values

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

Errors

getlogin returns a NULL pointer if the login name is not found. getlogin_r returns a value of 0 on success; a non-zero return indicates an error. The return value indicates the errno.

getlogin_r returns NULL and ERANGE when namelen is smaller than the length of the string.

References

cuserid(3S), getgrent(3C), getpwent(3C), utmp(4)

Notices

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

Use getlogin_r for multi-threaded applications.

The older getlogin_r interface:

   char *getlogin_r(char *name, size_t namelen);
is available if _SIMPLE_R is defined.
© 2004 The SCO Group, Inc. All rights reserved.
UnixWare 7 Release 7.1.4 - 25 April 2004