2 .\" Copyright 1995 James R. Van Zandt <jrv@vanzandt.mv.com>
4 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
6 .\" Changed Tue Sep 19 01:49:29 1995, aeb: moved from man2 to man3
7 .\" added ref to /etc/utmp, added BUGS section, etc.
8 .\" modified 2003 Walter Harms, aeb - added getlogin_r, note on stdin use
9 .TH getlogin 3 (date) "Linux man-pages (unreleased)"
11 getlogin, getlogin_r, cuserid \- get username
14 .RI ( libc ", " \-lc )
17 .B #include <unistd.h>
19 .B "char *getlogin(void);"
20 .BI "int getlogin_r(char " buf [. bufsize "], size_t " bufsize );
24 .BI "char *cuserid(char *" string );
28 Feature Test Macro Requirements for glibc (see
29 .BR feature_test_macros (7)):
34 .\" Deprecated: _REENTRANT ||
35 _POSIX_C_SOURCE >= 199506L
41 (_XOPEN_SOURCE && ! (_POSIX_C_SOURCE >= 200112L)
43 Up to and including glibc 2.23:
48 returns a pointer to a string containing the name of
49 the user logged in on the controlling terminal of the process, or a
50 null pointer if this information cannot be determined.
52 statically allocated and might be overwritten on subsequent calls to
57 returns this same username in the array
63 returns a pointer to a string containing a username
64 associated with the effective user ID of the process.
66 is not a null pointer, it should be an array that can hold at least
67 \fBL_cuserid\fP characters; the string is returned in this array.
68 Otherwise, a pointer to a string in a static area is returned.
70 string is statically allocated and might be overwritten on subsequent
71 calls to this function or to
74 The macro \fBL_cuserid\fP is an integer constant that indicates how
75 long an array you might need to store a username.
76 \fBL_cuserid\fP is declared in \fI<stdio.h>\fP.
78 These functions let your program identify positively the user who is
81 or the user who logged in this session
83 (These can differ when set-user-ID programs are involved.)
85 For most purposes, it is more useful to use the environment variable
86 \fBLOGNAME\fP to find out who the user is.
88 precisely because the user can set \fBLOGNAME\fP arbitrarily.
91 returns a pointer to the username when successful,
92 and NULL on failure, with
94 set to indicate the error.
96 returns 0 when successful, and nonzero on failure.
101 The per-process limit on the number of open file descriptors has been reached.
104 The system-wide limit on the total number of open files has been reached.
107 The calling process has no controlling terminal.
111 The length of the username, including the terminating null byte (\[aq]\e0\[aq]),
115 Linux/glibc also has:
118 There was no corresponding entry in the utmp-file.
121 Insufficient memory to allocate passwd structure.
124 Standard input didn't refer to a terminal.
129 password database file
132 (traditionally \fI/etc/utmp\fP;
133 some libc versions used \fI/var/adm/utmp\fP)
135 For an explanation of the terms used in this section, see
143 Interface Attribute Value
147 MT-Unsafe race:getlogin race:utent
148 sig:ALRM timer locale
153 MT-Unsafe race:utent sig:ALRM timer
159 MT-Unsafe race:cuserid/!string locale
169 signifies that if any of the functions
174 are used in parallel in different threads of a program,
175 then data races could occur.
179 call those functions,
180 so we use race:utent to remind users.
187 associated with a session, even if it has no controlling terminal.
206 System V, POSIX.1-1988.
207 Removed in POSIX.1-1990.
209 Removed in POSIX.1-2001.
213 function which uses the real
214 user ID rather than the effective user ID.
216 Unfortunately, it is often rather easy to fool
218 Sometimes it does not work at all, because some program messed up
220 Often, it gives only the first 8 characters of
222 The user currently logged in on the controlling terminal
223 of our program need not be the user who started it.
226 for security-related purposes.
228 Note that glibc does not follow the POSIX specification and uses
233 (Other recent systems, like SunOS 5.8 and HP-UX 11.11 and FreeBSD 4.8
234 all return the login name also when
238 Nobody knows precisely what
240 does; avoid it in portable programs.
241 Or avoid it altogether: use
242 .I getpwuid(geteuid())