1getlogin(3C) Standard C Library Functions getlogin(3C)
2
3
4
6 getlogin, getlogin_r - get login name
7
9 #include <unistd.h>
10
11 char *getlogin(void);
12
13
14 char *getlogin_r(char *name, int namelen);
15
16
17 Standard conforming
18 cc [ flag ... ] file... -D_POSIX_PTHREAD_SEMANTICS [ library ... ]
19
20 int getlogin_r(char *name, size_t namesize);
21
22
24 The getlogin() function returns a pointer to the login name as found in
25 /var/adm/utmpx. It can be used in conjunction with getpwnam(3C) to
26 locate the correct password file entry when the same user ID is shared
27 by several login names.
28
29
30 If getlogin() is called within a process that is not attached to a ter‐
31 minal, it returns a null pointer. The correct procedure for determining
32 the login name is to call cuserid(3C), or to call getlogin() and if it
33 fails to call getpwuid(3C).
34
35
36 The getlogin_r() function has the same functionality as getlogin()
37 except that the caller must supply a buffer name with length namelen to
38 store the result. The name buffer must be at least
39 _POSIX_LOGIN_NAME_MAX bytes in size (defined in <limits.h>). The POSIX
40 version (see standards(5)) of getlogin_r() takes a namesize parameter
41 of type size_t.
42
44 Upon successful completion, getlogin() returns a pointer to the login
45 name or a null pointer if the user's login name cannot be found. Oth‐
46 erwise it returns a null pointer and sets errno to indicate the error.
47
48
49 The standard-conforming getlogin_r() returns 0 if successful, or the
50 error number upon failure.
51
53 The getlogin_r() function will fail if:
54
55 ERANGE The size of the buffer is smaller than the result to be
56 returned.
57
58
59 EINVAL And entry for the current user was not found in the
60 /var/adm/utmpx file.
61
62
63
64 The getlogin() and getlogin_r() functions may fail if:
65
66 EMFILE There are {OPEN_MAX} file descriptors currently open in the
67 calling process.
68
69
70 ENFILE The maximum allowable number of files is currently open in
71 the system.
72
73
74 ENXIO The calling process has no controlling terminal.
75
76
77
78 The getlogin_r() function may fail if:
79
80 ERANGE The size of the buffer is smaller than the result to be
81 returned.
82
83
85 The return value of getlogin() points to thread-specific data whose
86 content is overwritten on each call by the same thread.
87
88
89 Three names associated with the current process can be determined: get‐
90 pwuid(geteuid()) returns the name associated with the effective user ID
91 of the process; getlogin() returns the name associated with the current
92 login activity; and getpwuid(getuid()) returns the name associated with
93 the real user ID of the process.
94
96 /var/adm/utmpx user access and administration information
97
98
100 See attributes(5) for descriptions of the following attributes:
101
102
103
104
105 ┌─────────────────────────────┬─────────────────────────────┐
106 │ ATTRIBUTE TYPE │ ATTRIBUTE VALUE │
107 ├─────────────────────────────┼─────────────────────────────┤
108 │Interface Stability │Standard │
109 ├─────────────────────────────┼─────────────────────────────┤
110 │MT-Level │See below. │
111 └─────────────────────────────┴─────────────────────────────┘
112
114 geteuid(2), getuid(2), cuserid(3C), getgrnam(3C), getpwnam(3C), getp‐
115 wuid(3C), utmpx(4), attributes(5), standards(5)
116
118 When compiling multithreaded programs, see Intro(3).
119
120
121 The getlogin() function is safe to use in multithreaded applications,
122 but is discouraged. The getlogin_r() function should be used instead.
123
124
125 Solaris 2.4 and earlier releases provided a getlogin_r() as specified
126 in POSIX.1c Draft 6. The final POSIX.1c standard changed the interface
127 as described above. Support for the Draft 6 interface is provided for
128 compatibility only and may not be supported in future releases. New
129 applications and libraries should use the standard-conforming inter‐
130 face.
131
132
133
134SunOS 5.11 18 May 2004 getlogin(3C)