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 2016-03-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)):
46 _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_\ <\ 500
48 Glibc 2.19 and earlier:
50 _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_\ <\ 500
56 returns the index of the current user's entry in some file.
58 Now "What file?" you ask.
59 Well, let's first look at some history.
61 There used to be a file
63 in UNIX\ V6, that was read by the
65 program to find out what to do with each terminal line.
66 Each line consisted of three characters.
67 The first character was either \(aq0\(aq or \(aq1\(aq,
68 where \(aq0\(aq meant "ignore".
69 The second character denoted the terminal: \(aq8\(aq stood for "/dev/tty8".
70 The third character was an argument to
72 indicating the sequence of line speeds to try (\(aq\-\(aq was: start trying
74 Thus a typical line was "18\-".
75 A hang on some line was solved by changing the \(aq1\(aq to a \(aq0\(aq,
76 signaling init, changing back again, and signaling init again.
78 In UNIX\ V7 the format was changed: here the second character
81 indicating the sequence of line speeds to try (\(aq0\(aq was: cycle through
82 300-1200-150-110 baud; \(aq4\(aq was for the on-line console DECwriter)
83 while the rest of the line contained the name of the tty.
84 Thus a typical line was "14console".
86 Later systems have more elaborate syntax.
87 System V-like systems have
90 .SS Ancient history (2)
91 On the other hand, there is the file
93 listing the people currently logged in.
96 It has a fixed size, and the appropriate index in the file was
101 call to find the number of the line in
104 .SS The semantics of ttyslot
107 returns the index of the controlling terminal of the calling process
110 and that is (usually) the same as the index of the entry for the
111 current user in the file
115 file, but System V-like systems do not, and hence cannot refer to it.
116 Thus, on such systems the documentation says that
118 returns the current user's index in the user accounting data base.
120 If successful, this function returns the slot number.
121 On error (e.g., if none of the file descriptors 0, 1 or 2 is
122 associated with a terminal that occurs in this data base)
123 it returns 0 on UNIX\ V6 and V7 and BSD-like systems,
124 but \-1 on System V-like systems.
126 For an explanation of the terms used in this section, see
132 Interface Attribute Value
135 T} Thread safety MT-Unsafe
138 SUSv1; marked as LEGACY in SUSv2; removed in POSIX.1-2001.
139 SUSv2 requires \-1 on error.
141 The utmp file is found in various places on various systems, such as
146 The glibc2 implementation of this function reads the file
151 It returns 0 on error.
152 Since Linux systems do not usually have "/etc/ttys", it will
155 On BSD-like systems and Linux, the declaration of
159 On Systsem V-like systems, the declaration is provided by
163 also provides the declaration with the following
164 feature test macro definitions:
168 (_XOPEN_SOURCE >= 500 ||
169 (_XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED))
170 && ! (_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600)
178 .\" appeared in UNIX V7.