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 2016-10-08 "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 _REENTRANT || _POSIX_C_SOURCE\ >=\ 199506L
53 (_XOPEN_SOURCE && ! (_POSIX_C_SOURCE >= 200112L)
55 Up to and including glibc 2.23:
60 returns a pointer to a string containing the name of
61 the user logged in on the controlling terminal of the process, or a
62 null pointer if this information cannot be determined.
64 statically allocated and might be overwritten on subsequent calls to
69 returns this same username in the array
75 returns a pointer to a string containing a username
76 associated with the effective user ID of the process.
78 is not a null pointer, it should be an array that can hold at least
79 \fBL_cuserid\fP characters; the string is returned in this array.
80 Otherwise, a pointer to a string in a static area is returned.
82 string is statically allocated and might be overwritten on subsequent
83 calls to this function or to
86 The macro \fBL_cuserid\fP is an integer constant that indicates how
87 long an array you might need to store a username.
88 \fBL_cuserid\fP is declared in \fI<stdio.h>\fP.
90 These functions let your program identify positively the user who is
93 or the user who logged in this session
95 (These can differ when set-user-ID programs are involved.)
97 For most purposes, it is more useful to use the environment variable
98 \fBLOGNAME\fP to find out who the user is.
100 precisely because the user can set \fBLOGNAME\fP arbitrarily.
103 returns a pointer to the username when successful,
104 and NULL on failure, with
106 set to indicate the cause of the error.
108 returns 0 when successful, and nonzero on failure.
113 The per-process limit on the number of open file descriptors has been reached.
116 The system-wide limit on the total number of open files has been reached.
119 The calling process has no controlling terminal.
123 The length of the username, including the terminating null byte (\(aq\\0\(aq),
130 There was no corresponding entry in the utmp-file.
133 Insufficient memory to allocate passwd structure.
136 Standard input didn't refer to a terminal.
141 password database file
144 (traditionally \fI/etc/utmp\fP;
145 some libc versions used \fI/var/adm/utmp\fP)
147 For an explanation of the terms used in this section, see
153 Interface Attribute Value
157 MT-Unsafe race:getlogin race:utent
159 sig:ALRM timer locale
164 MT-Unsafe race:utent sig:ALRM timer
170 T} Thread safety MT-Unsafe race:cuserid/!string locale
177 signifies that if any of the functions
182 are used in parallel in different threads of a program,
183 then data races could occur.
187 call those functions,
188 so we use race:utent to remind users.
193 POSIX.1-2001, POSIX.1-2008.
197 function which uses the real
198 user ID rather than the effective user ID.
202 was included in the 1988 version of POSIX,
203 but removed from the 1990 version.
204 It was present in SUSv2, but removed in POSIX.1-2001.
211 associated with a session, even if it has no controlling terminal.
213 Unfortunately, it is often rather easy to fool
215 Sometimes it does not work at all, because some program messed up
217 Often, it gives only the first 8 characters of
219 The user currently logged in on the controlling terminal
220 of our program need not be the user who started it.
223 for security-related purposes.
225 Note that glibc does not follow the POSIX specification and uses
230 (Other recent systems, like SunOS 5.8 and HP-UX 11.11 and FreeBSD 4.8
231 all return the login name also when
235 Nobody knows precisely what
237 does; avoid it in portable programs.
238 Or avoid it altogether: use
239 .I getpwuid(geteuid())