getlogin(3) Library Functions Manual getlogin(3) getlogin, getlogin_r, cuserid - LIBRARY Standard C library (libc, -lc) #include char *getlogin(void); int getlogin_r(char buf[.bufsize], size_t bufsize); #include char *cuserid(char *string); glibc (. feature_test_macros(7)): getlogin_r(): _POSIX_C_SOURCE >= 199506L cuserid(): Since glibc 2.24: (_XOPEN_SOURCE && ! (_POSIX_C_SOURCE >= 200112L) || _GNU_SOURCE Up to and including glibc 2.23: _XOPEN_SOURCE getlogin() , , c , , null, . cuserid(). getlogin_r() , buf bufsize. cuserid() , , . string null, , L_cuserid ; . . getlogin(). L_cuserid , , . L_cuserid . (cuserid()) (getlogin()) ( , set-user-ID). LOGNAME, LOGNAME . getlogin() returns a pointer to the username when successful, and NULL on failure, with errno set to indicate the error. getlogin_r() returns 0 when successful, and nonzero on failure. POSIX : EMFILE . ENFILE . ENXIO . ERANGE (getlogin_r) The length of the username, including the terminating null byte ('\0'), is larger than bufsize. Linux/glibc : ENOENT utmp. ENOMEM passwd. ENOTTY ( ). /etc/passwd , /var/run/utmp (, /etc/utmp; libc /var/adm/utmp) attributes(7). +----------------------------+----------------------------------------------------------+--------------------------+ | | | | +----------------------------+----------------------------------------------------------+--------------------------+ |getlogin() | | MT-Unsafe race:getlogin | | | | race:utent sig:ALRM | | | | timer locale | +----------------------------+----------------------------------------------------------+--------------------------+ |getlogin_r() | | MT-Unsafe race:utent | | | | sig:ALRM timer locale | +----------------------------+----------------------------------------------------------+--------------------------+ |cuserid() | | MT-Unsafe | | | | race:cuserid/!string | | | | locale | +----------------------------+----------------------------------------------------------+--------------------------+ utent race:utent , setutent(3), getutent(3) endutent(3) , . getlogin() getlogin_r() race:utent . OpenBSD getlogin() setlogin(), . getlogin() getlogin_r() POSIX.1-2008. cuserid() None. getlogin() getlogin_r(): POSIX.1-2001. OpenBSD. cuserid() System V, POSIX.1-1988. Removed in POSIX.1-1990. SUSv2. Removed in POSIX.1-2001. System V has a cuserid() function which uses the real user ID rather than the effective user ID. , <<>> getlogin(). - , - utmp. 8 . , , , , . getlogin() . , glibc POSIX stdin /dev/tty. ( , SunOS 5.8, HP-UX 11.11 FreeBSD 4.8, stdin). cuserid(), . getpwuid(geteuid()), . cuserid(). . logname(1), geteuid(2), getuid(2), utmp(5) Azamat Hackimov , Dmitry Bolkhovskikh , Vladislav , Yuri Kozlov ; GNU 3 , . . , , . Linux man-pages 6.06 31 2023 . getlogin(3)