]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man3/ttyslot.3
ttyslot.3: Clarify details of use of <stdlib.h> file
[thirdparty/man-pages.git] / man3 / ttyslot.3
1 .\" Copyright (C) 2002 Andries Brouwer <aeb@cwi.nl>
2 .\"
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.
7 .\"
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.
12 .\"
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
19 .\" professionally.
20 .\"
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
23 .\" %%%LICENSE_END
24 .\"
25 .\" This replaces an earlier man page written by Walter Harms
26 .\" <walter.harms@informatik.uni-oldenburg.de>.
27 .\"
28 .TH TTYSLOT 3 2016-03-15 "GNU" "Linux Programmer's Manual"
29 .SH NAME
30 ttyslot \- find the slot of the current user's terminal in some file
31 .SH SYNOPSIS
32 .BR "#include <unistd.h>" " /See NOTES */"
33 .sp
34 .B "int ttyslot(void);"
35 .sp
36 .in -4n
37 Feature Test Macro Requirements for glibc (see
38 .BR feature_test_macros (7)):
39 .in
40 .sp
41 .ad l
42 .BR ttyslot ():
43 .RS 4
44 Since glibc 2.20:
45 _BSD_SOURCE ||
46 _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_\ <\ 500
47 .br
48 Glibc 2.19 and earlier:
49 _DEFAULT_SOURCE ||
50 _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_\ <\ 500
51 .RE
52 .ad b
53 .SH DESCRIPTION
54 The legacy function
55 .BR ttyslot ()
56 returns the index of the current user's entry in some file.
57 .LP
58 Now "What file?" you ask.
59 Well, let's first look at some history.
60 .SS Ancient history
61 There used to be a file
62 .I /etc/ttys
63 in UNIX\ V6, that was read by the
64 .BR init (1)
65 program to find out what to do with each terminal line.
66 Each line consisted of three characters.
67 The first character was either \(aq0\(aq or \(aq1\(aq,
68 where \(aq0\(aq meant "ignore".
69 The second character denoted the terminal: \(aq8\(aq stood for "/dev/tty8".
70 The third character was an argument to
71 .BR getty (8)
72 indicating the sequence of line speeds to try (\(aq\-\(aq was: start trying
73 110 baud).
74 Thus a typical line was "18\-".
75 A hang on some line was solved by changing the \(aq1\(aq to a \(aq0\(aq,
76 signaling init, changing back again, and signaling init again.
77 .LP
78 In UNIX\ V7 the format was changed: here the second character
79 was the argument to
80 .BR getty (8)
81 indicating the sequence of line speeds to try (\(aq0\(aq was: cycle through
82 300-1200-150-110 baud; \(aq4\(aq was for the on-line console DECwriter)
83 while the rest of the line contained the name of the tty.
84 Thus a typical line was "14console".
85 .LP
86 Later systems have more elaborate syntax.
87 System V-like systems have
88 .I /etc/inittab
89 instead.
90 .SS Ancient history (2)
91 On the other hand, there is the file
92 .I /etc/utmp
93 listing the people currently logged in.
94 It is maintained by
95 .BR login (1).
96 It has a fixed size, and the appropriate index in the file was
97 determined by
98 .BR login (1)
99 using the
100 .BR ttyslot ()
101 call to find the number of the line in
102 .I /etc/ttys
103 (counting from 1).
104 .SS The semantics of ttyslot
105 Thus, the function
106 .BR ttyslot ()
107 returns the index of the controlling terminal of the calling process
108 in the file
109 .IR /etc/ttys ,
110 and that is (usually) the same as the index of the entry for the
111 current user in the file
112 .IR /etc/utmp .
113 BSD still has the
114 .I /etc/ttys
115 file, but System V-like systems do not, and hence cannot refer to it.
116 Thus, on such systems the documentation says that
117 .BR ttyslot ()
118 returns the current user's index in the user accounting data base.
119 .SH RETURN VALUE
120 If successful, this function returns the slot number.
121 On error (e.g., if none of the file descriptors 0, 1 or 2 is
122 associated with a terminal that occurs in this data base)
123 it returns 0 on UNIX\ V6 and V7 and BSD-like systems,
124 but \-1 on System V-like systems.
125 .SH ATTRIBUTES
126 For an explanation of the terms used in this section, see
127 .BR attributes (7).
128 .TS
129 allbox;
130 lb lb lb
131 l l l.
132 Interface Attribute Value
133 T{
134 .BR ttyslot ()
135 T} Thread safety MT-Unsafe
136 .TE
137 .SH CONFORMING TO
138 SUSv1; marked as LEGACY in SUSv2; removed in POSIX.1-2001.
139 SUSv2 requires \-1 on error.
140 .SH NOTES
141 The utmp file is found in various places on various systems, such as
142 .IR /etc/utmp ,
143 .IR /var/adm/utmp ,
144 .IR /var/run/utmp .
145 .LP
146 The glibc2 implementation of this function reads the file
147 .BR _PATH_TTYS ,
148 defined in
149 .I <ttyent.h>
150 as "/etc/ttys".
151 It returns 0 on error.
152 Since Linux systems do not usually have "/etc/ttys", it will
153 always return 0.
154 .PP
155 On BSD-like systems and Linux, the declaration of
156 .BR ttyslot ()
157 is provided by
158 .IR <unistd.h> .
159 On Systsem V-like systems, the declaration is provided by
160 .IR <stdlib.h> .
161 Since glibc 2.24,
162 .IR <stdlib.h>
163 also provides the declaration with the following
164 feature test macro definitions:
165 .PP
166 .nf
167 .in +4n
168 (_XOPEN_SOURCE >= 500 ||
169 (_XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED))
170 && ! (_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600)
171 .in
172 .fi
173 .PP
174 Minix also has
175 .IR fttyslot ( fd ).
176 .\" .SH HISTORY
177 .\" .BR ttyslot ()
178 .\" appeared in UNIX V7.
179 .SH SEE ALSO
180 .BR getttyent (3),
181 .BR ttyname (3),
182 .BR utmp (5)