1GETLOGIN(3) Linux Programmer's Manual GETLOGIN(3)
2
3
4
6 getlogin, getlogin_r, cuserid - get username
7
9 #include <unistd.h>
10
11 char *getlogin(void);
12 int getlogin_r(char *buf, size_t bufsize);
13
14 #include <stdio.h>
15
16 char *cuserid(char *string);
17
18 Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
19
20 getlogin_r(): _POSIX_C_SOURCE >= 199506L
21
22 cuserid():
23 Since glibc 2.24:
24 (_XOPEN_SOURCE && ! (_POSIX_C_SOURCE >= 200112L)
25 || _GNU_SOURCE
26 Up to and including glibc 2.23:
27 _XOPEN_SOURCE
28
30 getlogin() returns a pointer to a string containing the name of the
31 user logged in on the controlling terminal of the process, or a null
32 pointer if this information cannot be determined. The string is stati‐
33 cally allocated and might be overwritten on subsequent calls to this
34 function or to cuserid().
35
36 getlogin_r() returns this same username in the array buf of size buf‐
37 size.
38
39 cuserid() returns a pointer to a string containing a username associ‐
40 ated with the effective user ID of the process. If string is not a
41 null pointer, it should be an array that can hold at least L_cuserid
42 characters; the string is returned in this array. Otherwise, a pointer
43 to a string in a static area is returned. This string is statically
44 allocated and might be overwritten on subsequent calls to this function
45 or to getlogin().
46
47 The macro L_cuserid is an integer constant that indicates how long an
48 array you might need to store a username. L_cuserid is declared in
49 <stdio.h>.
50
51 These functions let your program identify positively the user who is
52 running (cuserid()) or the user who logged in this session (getlo‐
53 gin()). (These can differ when set-user-ID programs are involved.)
54
55 For most purposes, it is more useful to use the environment variable
56 LOGNAME to find out who the user is. This is more flexible precisely
57 because the user can set LOGNAME arbitrarily.
58
60 getlogin() returns a pointer to the username when successful, and NULL
61 on failure, with errno set to indicate the cause of the error. getlo‐
62 gin_r() returns 0 when successful, and nonzero on failure.
63
65 POSIX specifies
66
67 EMFILE The per-process limit on the number of open file descriptors has
68 been reached.
69
70 ENFILE The system-wide limit on the total number of open files has been
71 reached.
72
73 ENXIO The calling process has no controlling terminal.
74
75 ERANGE (getlogin_r) The length of the username, including the terminat‐
76 ing null byte ('\0'), is larger t