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