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 2017-09-15 "GNU" "Linux Programmer's Manual"
30 ttyslot \- find the slot of the current user's terminal in some file
32 .BR "#include <unistd.h>" " /See NOTES */"
34 .B "int ttyslot(void);"
37 Feature Test Macro Requirements for glibc (see
38 .BR feature_test_macros (7)):
47 From glibc 2.20 to 2.23:
49 _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE\ <\ 500
51 Glibc 2.19 and earlier:
53 _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE\ <\ 500
59 returns the index of the current user's entry in some file.
61 Now "What file?" you ask.
62 Well, let's first look at some history.
64 There used to be a file
66 in UNIX\ V6, that was read by the
68 program to find out what to do with each terminal line.
69 Each line consisted of three characters.
70 The first character was either \(aq0\(aq or \(aq1\(aq,
71 where \(aq0\(aq meant "ignore".
72 The second character denoted the terminal: \(aq8\(aq stood for "/dev/tty8".
73 The third character was an argument to
75 indicating the sequence of line speeds to try (\(aq\-\(aq was: start trying
77 Thus a typical line was "18\-".
78 A hang on some line was solved by changing the \(aq1\(aq to a \(aq0\(aq,
79 signaling init, changing back again, and signaling init again.
81 In UNIX\ V7 the format was changed: here the second character
84 indicating the sequence of line speeds to try (\(aq0\(aq was: cycle through
85 300-1200-150-110 baud; \(aq4\(aq was for the on-line console DECwriter)
86 while the rest of the line contained the name of the tty.
87 Thus a typical line was "14console".
89 Later systems have more elaborate syntax.
90 System V-like systems have
93 .SS Ancient history (2)
94 On the other hand, there is the file
96 listing the people currently logged in.
99 It has a fixed size, and the appropriate index in the file was
104 call to find the number of the line in
107 .SS The semantics of ttyslot
110 returns the index of the controlling terminal of the calling process
113 and that is (usually) the same as the index of the entry for the
114 current user in the file
118 file, but System V-like systems do not, and hence cannot refer to it.
119 Thus, on such systems the documentation says that
121 returns the current user's index in the user accounting data base.
123 If successful, this function returns the slot number.
124 On error (e.g., if none of the file descriptors 0, 1 or 2 is
125 associated with a terminal that occurs in this data base)
126 it returns 0 on UNIX\ V6 and V7 and BSD-like systems,
127 but \-1 on System V-like systems.
129 For an explanation of the terms used in this section, see
135 Interface Attribute Value
138 T} Thread safety MT-Unsafe
141 SUSv1; marked as LEGACY in SUSv2; removed in POSIX.1-2001.
142 SUSv2 requires \-1 on error.
144 The utmp file is found in various places on various systems, such as
149 The glibc2 implementation of this function reads the file
154 It returns 0 on error.
155 Since Linux systems do not usually have "/etc/ttys", it will
158 On BSD-like systems and Linux, the declaration of
162 On System V-like systems, the declaration is provided by
166 also provides the declaration with the following
167 feature test macro definitions:
171 (_XOPEN_SOURCE >= 500 ||
172 (_XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED))
173 && ! (_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600)
181 .\" appeared in UNIX V7.