1 .\" Copyright 1995 James R. Van Zandt <jrv@vanzandt.mv.com>
3 .\" %%%LICENSE_START(VERBATIM)
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date. The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein. The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
25 .\" Changed Tue Sep 19 01:49:29 1995, aeb: moved from man2 to man3
26 .\" added ref to /etc/utmp, added BUGS section, etc.
27 .\" modified 2003 Walter Harms, aeb - added getlogin_r, note on stdin use
28 .TH GETLOGIN 3 2017-09-15 "GNU" "Linux Programmer's Manual"
30 getlogin, getlogin_r, cuserid \- get username
32 .B #include <unistd.h>
34 .B "char *getlogin(void);"
36 .BI "int getlogin_r(char *" buf ", size_t " bufsize );
40 .BI "char *cuserid(char *" string );
43 Feature Test Macro Requirements for glibc (see
44 .BR feature_test_macros (7)):
48 .\" Deprecated: _REENTRANT ||
49 _POSIX_C_SOURCE\ >=\ 199506L
54 (_XOPEN_SOURCE && ! (_POSIX_C_SOURCE >= 200112L)
56 Up to and including glibc 2.23:
61 returns a pointer to a string containing the name of
62 the user logged in on the controlling terminal of the process, or a
63 null pointer if this information cannot be determined.
65 statically allocated and might be overwritten on subsequent calls to
70 returns this same username in the array
76 returns a pointer to a string containing a username
77 associated with the effective user ID of the process.
79 is not a null pointer, it should be an array that can hold at least
80 \fBL_cuserid\fP characters; the string is returned in this array.
81 Otherwise, a pointer to a string in a static area is returned.
83 string is statically allocated and might be overwritten on subsequent
84 calls to this function or to
87 The macro \fBL_cuserid\fP is an integer constant that indicates how
88 long an array you might need to store a username.
89 \fBL_cuserid\fP is declared in \fI<stdio.h>\fP.
91 These functions let your program identify positively the user who is
94 or the user who logged in this session
96 (These can differ when set-user-ID programs are involved.)
98 For most purposes, it is more useful to use the environment variable
99 \fBLOGNAME\fP to find out who the user is.
100 This is more flexible
101 precisely because the user can set \fBLOGNAME\fP arbitrarily.
104 returns a pointer to the username when successful,
105 and NULL on failure, with
107 set to indicate the cause of the error.
109 returns 0 when successful, and nonzero on failure.
114 The per-process limit on the number of open file descriptors has been reached.
117 The system-wide limit on the total number of open files has been reached.
120 The calling process has no controlling terminal.
124 The length of the username, including the terminating null byte (\(aq\\0\(aq),
131 There was no corresponding entry in the utmp-file.
134 Insufficient memory to allocate passwd structure.
137 Standard input didn't refer to a terminal.
142 password database file
145 (traditionally \fI/etc/utmp\fP;
146 some libc versions used \fI/var/adm/utmp\fP)
148 For an explanation of the terms used in this section, see
154 Interface Attribute Value
158 MT-Unsafe race:getlogin race:utent
160 sig:ALRM timer locale
165 MT-Unsafe race:utent sig:ALRM timer
171 T} Thread safety MT-Unsafe race:cuserid/!string locale
178 signifies that if any of the functions
183 are used in parallel in different threads of a program,
184 then data races could occur.
188 call those functions,
189 so we use race:utent to remind users.
194 POSIX.1-2001, POSIX.1-2008.
198 function which uses the real
199 user ID rather than the effective user ID.
203 was included in the 1988 version of POSIX,
204 but removed from the 1990 version.
205 It was present in SUSv2, but removed in POSIX.1-2001.
212 associated with a session, even if it has no controlling terminal.
214 Unfortunately, it is often rather easy to fool
216 Sometimes it does not work at all, because some program messed up
218 Often, it gives only the first 8 characters of
220 The user currently logged in on the controlling terminal
221 of our program need not be the user who started it.
224 for security-related purposes.
226 Note that glibc does not follow the POSIX specification and uses
231 (Other recent systems, like SunOS 5.8 and HP-UX 11.11 and FreeBSD 4.8
232 all return the login name also when
236 Nobody knows precisely what
238 does; avoid it in portable programs.
239 Or avoid it altogether: use
240 .I getpwuid(geteuid())