1 .\" Copyright (C) 2002 Andries Brouwer <aeb@cwi.nl>
3 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
5 .\" This replaces an earlier man page written by Walter Harms
6 .\" <walter.harms@informatik.uni-oldenburg.de>.
8 .TH TTYSLOT 3 2021-03-22 "Linux man-pages (unreleased)"
10 ttyslot \- find the slot of the current user's terminal in some file
13 .RI ( libc ", " \-lc )
16 .BR "#include <unistd.h>" " /* See NOTES */"
18 .B "int ttyslot(void);"
22 Feature Test Macro Requirements for glibc (see
23 .BR feature_test_macros (7)):
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)
38 returns the index of the current user's entry in some file.
40 Now "What file?" you ask.
41 Well, let's first look at some history.
43 There used to be a file
45 in UNIX\ V6, that was read by the
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
54 indicating the sequence of line speeds to try (\(aq\-\(aq was: start trying
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.
60 In UNIX\ V7 the format was changed: here the second character
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".
68 Later systems have more elaborate syntax.
69 System V-like systems have
72 .SS Ancient history (2)
73 On the other hand, there is the file
75 listing the people currently logged in.
78 It has a fixed size, and the appropriate index in the file was
83 call to find the number of the line in
86 .SS The semantics of ttyslot
89 returns the index of the controlling terminal of the calling process
92 and that is (usually) the same as the index of the entry for the
93 current user in the file
97 file, but System V-like systems do not, and hence cannot refer to it.
98 Thus, on such systems the documentation says that
100 returns the current user's index in the user accounting data base.
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.
108 For an explanation of the terms used in this section, see
116 Interface Attribute Value
119 T} Thread safety MT-Unsafe
125 SUSv1; marked as LEGACY in SUSv2; removed in POSIX.1-2001.
126 SUSv2 requires \-1 on error.
128 The utmp file is found in various places on various systems, such as
133 The glibc2 implementation of this function reads the file
138 It returns 0 on error.
139 Since Linux systems do not usually have "/etc/ttys", it will
142 On BSD-like systems and Linux, the declaration of
146 On System V-like systems, the declaration is provided by
150 also provides the declaration with the following
151 feature test macro definitions:
155 (_XOPEN_SOURCE >= 500 ||
156 (_XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED))
157 && ! (_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600)
165 .\" appeared in UNIX V7.