1 .\" Copyright (C) 2002 Andries Brouwer <aeb@cwi.nl>
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.
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.
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
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
25 .\" This replaces an earlier man page written by Walter Harms
26 .\" <walter.harms@informatik.uni-oldenburg.de>.
28 .TH TTYSLOT 3 2021-03-22 "GNU" "Linux Programmer's Manual"
30 ttyslot \- find the slot of the current user's terminal in some file
33 .BR "#include <unistd.h>" " /* See NOTES */"
35 .B "int ttyslot(void);"
39 Feature Test Macro Requirements for glibc (see
40 .BR feature_test_macros (7)):
47 From glibc 2.20 to 2.23:
48 _DEFAULT_SOURCE || (_XOPEN_SOURCE && _XOPEN_SOURCE < 500)
49 Glibc 2.19 and earlier:
50 _BSD_SOURCE || (_XOPEN_SOURCE && _XOPEN_SOURCE < 500)
55 returns the index of the current user's entry in some file.
57 Now "What file?" you ask.
58 Well, let's first look at some history.
60 There used to be a file
62 in UNIX\ V6, that was read by the
64 program to find out what to do with each terminal line.
65 Each line consisted of three characters.
66 The first character was either \(aq0\(aq or \(aq1\(aq,
67 where \(aq0\(aq meant "ignore".
68 The second character denoted the terminal: \(aq8\(aq stood for "/dev/tty8".
69 The third character was an argument to
71 indicating the sequence of line speeds to try (\(aq\-\(aq was: start trying
73 Thus a typical line was "18\-".
74 A hang on some line was solved by changing the \(aq1\(aq to a \(aq0\(aq,
75 signaling init, changing back again, and signaling init again.
77 In UNIX\ V7 the format was changed: here the second character
80 indicating the sequence of line speeds to try (\(aq0\(aq was: cycle through
81 300-1200-150-110 baud; \(aq4\(aq was for the on-line console DECwriter)
82 while the rest of the line contained the name of the tty.
83 Thus a typical line was "14console".
85 Later systems have more elaborate syntax.
86 System V-like systems have
89 .SS Ancient history (2)
90 On the other hand, there is the file
92 listing the people currently logged in.
95 It has a fixed size, and the appropriate index in the file was
100 call to find the number of the line in
103 .SS The semantics of ttyslot
106 returns the index of the controlling terminal of the calling process
109 and that is (usually) the same as the index of the entry for the
110 current user in the file
114 file, but System V-like systems do not, and hence cannot refer to it.
115 Thus, on such systems the documentation says that
117 returns the current user's index in the user accounting data base.
119 If successful, this function returns the slot number.
120 On error (e.g., if none of the file descriptors 0, 1, or 2 is
121 associated with a terminal that occurs in this data base)
122 it returns 0 on UNIX\ V6 and V7 and BSD-like systems,
123 but \-1 on System V-like systems.
125 For an explanation of the terms used in this section, see
133 Interface Attribute Value
136 T} Thread safety MT-Unsafe
142 SUSv1; marked as LEGACY in SUSv2; removed in POSIX.1-2001.
143 SUSv2 requires \-1 on error.
145 The utmp file is found in various places on various systems, such as
150 The glibc2 implementation of this function reads the file
155 It returns 0 on error.
156 Since Linux systems do not usually have "/etc/ttys", it will
159 On BSD-like systems and Linux, the declaration of
163 On System V-like systems, the declaration is provided by
167 also provides the declaration with the following
168 feature test macro definitions:
172 (_XOPEN_SOURCE >= 500 ||
173 (_XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED))
174 && ! (_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600)
182 .\" appeared in UNIX V7.