getlogin(3C) getlogin(3C)
getlogin, getlogin_r - get login name
#include <unistd.h>
char *getlogin (void);
int getlogin_r (char *name, size_t namelen);
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 is a reentrant version of getlogin. The login name is copied
into the character array pointed to by name. The array is namelen long
and should have space for the name and the terminating null character.
The maximum size of the login name is {LOGIN_NAME_MAX}. sysconf(3C) may
be used to determine this value.
The following error can be returned by getlogin_r:
ERANGE The value of namelen is smaller than the length of the
string to be returned.
/var/adm/utmp
cuserid(3S), getgrent(3C), getpwent(3C), sysconf(3C), utmp(4)
getlogin returns a null pointer if the login name is not found.
getlogin_r returns 0 on success or a an error number on failure.
The return values point to static data whose content is overwritten by
each call.
PPPPaaaaggggeeee 1111 [ Back ]
|