getlogin(3C) getlogin(3C)
NAME
getlogin, getlogin_r - get login name
SYNOPSIS
#include <stdlib.h>
char *getlogin(void);
char *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 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.
Errors
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.
Copyright 1994 Novell, Inc. Page 1
getlogin(3C) getlogin(3C)
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.
Copyright 1994 Novell, Inc. Page 2