getlogin -- Determine User Login Name


SYNOPSIS
#include <unistd.h>
char *getlogin(void);
DESCRIPTION
getlogin
returns the login name for the current process. Under
OpenEdition MVS, this is the same as the userid defined for the
batch job or TSO session that generated the process. The name string is
stored in a static area and may be overwritten by subsequent calls to
getlogin
. The getlogin
function fails if OpenEdition is not active
or installed.
RETURN VALUE
getlogin
returns a pointer to the name string if successful, and
a NULL pointer if unsuccessful.
EXAMPLE
This example tests to see if the effective user ID is the ID belonging
to the login name.
#include <sys/types.h>
#include <unistd.h>
#include <pwd.h>
#include <stdio.h>
#include <stdlib.h>
main() {
char *name;
struct passwd *unifo;
name = getlogin();
if (!name) {
perror("getlogin failure");
exit(EXIT_FAILURE);
}
unifo = getpwnam(name);
if (!unifo) {
perror("getpwnam failure");
exit(EXIT_FAILURE);
}
if (unifo->pw_uid == geteuid())
puts("Your user ID number matches the effective user ID.");
else
puts("Your user ID does not match the effective user ID.");
exit(EXIT_SUCCESS);
}
RELATED FUNCTIONS
cuserid
SEE ALSO