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