__getlogin1() — Get the user login name
Standards
Standards / Extensions | C or C++ | Dependencies |
---|---|---|
POSIX.1 |
both |
Format
#define _POSIX_SOURCE
#include <unistd.h>
char *__getlogin1(void);
General description
Finds the name that the login process associated with the current terminal. If called from batch, __getlogin1() finds the name associated with the batch program. With z/OS® UNIX services, this name is a TSO/E user ID unless the USERIDALISTABLE is in use. If the USERIDALISTABLE is setup and a z/OS UNIX alias name exists for a given MVS(TSO, batch user, etc.) userid, then that will be returned.
If __getlogin1() cannot determine the login name, you can call getuid() to get the user ID of the process, and then call getpwuid() to get a login name associated with that user ID. getpwuid() always returns the passwd struct for the same user, even if multiple users have the same UID.
Returned value
If successful, __getlogin1() returns a pointer to a string that has the login name for the current terminal.
If unsuccessful, __getlogin1() returns the NULL pointer.
There are no documented errno values.
Example
/* CELEBG12
This example gets the user login name.
*/
#define _POSIX_SOURCE
#include <stdio.h>
#include <unistd.h>
main() {
char *user;
if ((user = __getlogin1()) == NULL)
perror("__getlogin1() error");
else printf("__getlogin1() returned %s\n", user);
}
getlogin() returned MEGA