2 .\" Copyright (C) 2002 Andries Brouwer <aeb@cwi.nl>
4 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
6 .\" This replaces an earlier man page written by Walter Harms
7 .\" <walter.harms@informatik.uni-oldenburg.de>.
9 .TH ttyslot 3 (date) "Linux man-pages (unreleased)"
11 ttyslot \- find the slot of the current user's terminal in some file
14 .RI ( libc ", " \-lc )
17 .BR "#include <unistd.h>" " /* See NOTES */"
19 .B "int ttyslot(void);"
23 Feature Test Macro Requirements for glibc (see
24 .BR feature_test_macros (7)):
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)
39 returns the index of the current user's entry in some file.
41 Now "What file?" you ask.
42 Well, let's first look at some history.
44 There used to be a file
46 in UNIX\ V6, that was read by the
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
55 indicating the sequence of line speeds to try (\[aq]\-\[aq] was: start trying
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.
61 In UNIX\ V7 the format was changed: here the second character
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".
69 Later systems have more elaborate syntax.
70 System V-like systems have
73 .SS Ancient history (2)
74 On the other hand, there is the file
76 listing the people currently logged in.
79 It has a fixed size, and the appropriate index in the file was
84 call to find the number of the line in
87 .SS The semantics of ttyslot
90 returns the index of the controlling terminal of the calling process
93 and that is (usually) the same as the index of the entry for the
94 current user in the file
98 file, but System V-like systems do not, and hence cannot refer to it.
99 Thus, on such systems the documentation says that
101 returns the current user's index in the user accounting data base.
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.
109 For an explanation of the terms used in this section, see
117 Interface Attribute Value
120 T} Thread safety MT-Unsafe
126 SUSv1; marked as LEGACY in SUSv2; removed in POSIX.1-2001.
127 SUSv2 requires \-1 on error.
129 The utmp file is found in various places on various systems, such as
134 The glibc2 implementation of this function reads the file
139 It returns 0 on error.
140 Since Linux systems do not usually have "/etc/ttys", it will
143 On BSD-like systems and Linux, the declaration of
147 On System V-like systems, the declaration is provided by
151 also provides the declaration with the following
152 feature test macro definitions:
156 (_XOPEN_SOURCE >= 500 ||
157 (_XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED))
158 && ! (_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600)
166 .\" appeared in UNIX V7.