#include <unistd.h> char *getlogin(void);
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.
getlogin
returns a pointer to the name string if successful, and
a NULL pointer if unsuccessful.
#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); }
cuserid
Copyright (c) 1998 SAS Institute Inc. Cary, NC, USA. All rights reserved.