mbrtowc.3: SYNOPSIS: Use 'restrict' in prototypes
[man-pages.git] / man3 / ttyslot.3
blob1e65901cb133a8e97cdccc74200ddbf915c287ac
1 .\" Copyright (C) 2002 Andries Brouwer <aeb@cwi.nl>
2 .\"
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.
7 .\"
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.
12 .\"
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
19 .\" professionally.
20 .\"
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
23 .\" %%%LICENSE_END
24 .\"
25 .\" This replaces an earlier man page written by Walter Harms
26 .\" <walter.harms@informatik.uni-oldenburg.de>.
27 .\"
28 .TH TTYSLOT 3 2017-09-15 "GNU" "Linux Programmer's Manual"
29 .SH NAME
30 ttyslot \- find the slot of the current user's terminal in some file
31 .SH SYNOPSIS
32 .nf
33 .BR "#include <unistd.h>" "       /See NOTES */"
34 .PP
35 .B "int ttyslot(void);"
36 .fi
37 .PP
38 .RS -4
39 Feature Test Macro Requirements for glibc (see
40 .BR feature_test_macros (7)):
41 .RE
42 .PP
43 .BR ttyslot ():
44 .nf
45     Since glibc 2.24:
46         _DEFAULT_SOURCE
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)
51 .fi
52 .SH DESCRIPTION
53 The legacy function
54 .BR ttyslot ()
55 returns the index of the current user's entry in some file.
56 .PP
57 Now "What file?" you ask.
58 Well, let's first look at some history.
59 .SS Ancient history
60 There used to be a file
61 .I /etc/ttys
62 in UNIX\ V6, that was read by the
63 .BR init (1)
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
70 .BR getty (8)
71 indicating the sequence of line speeds to try (\(aq\-\(aq was: start trying
72 110 baud).
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.
76 .PP
77 In UNIX\ V7 the format was changed: here the second character
78 was the argument to
79 .BR getty (8)
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".
84 .PP
85 Later systems have more elaborate syntax.
86 System V-like systems have
87 .I /etc/inittab
88 instead.
89 .SS Ancient history (2)
90 On the other hand, there is the file
91 .I /etc/utmp
92 listing the people currently logged in.
93 It is maintained by
94 .BR login (1).
95 It has a fixed size, and the appropriate index in the file was
96 determined by
97 .BR login (1)
98 using the
99 .BR ttyslot ()
100 call to find the number of the line in
101 .I /etc/ttys
102 (counting from 1).
103 .SS The semantics of ttyslot
104 Thus, the function
105 .BR ttyslot ()
106 returns the index of the controlling terminal of the calling process
107 in the file
108 .IR /etc/ttys ,
109 and that is (usually) the same as the index of the entry for the
110 current user in the file
111 .IR /etc/utmp .
112 BSD still has the
113 .I /etc/ttys
114 file, but System V-like systems do not, and hence cannot refer to it.
115 Thus, on such systems the documentation says that
116 .BR ttyslot ()
117 returns the current user's index in the user accounting data base.
118 .SH RETURN VALUE
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.
124 .SH ATTRIBUTES
125 For an explanation of the terms used in this section, see
126 .BR attributes (7).
127 .ad l
130 allbox;
131 lbx lb lb
132 l l l.
133 Interface       Attribute       Value
135 .BR ttyslot ()
136 T}      Thread safety   MT-Unsafe
140 .sp 1
141 .SH CONFORMING TO
142 SUSv1; marked as LEGACY in SUSv2; removed in POSIX.1-2001.
143 SUSv2 requires \-1 on error.
144 .SH NOTES
145 The utmp file is found in various places on various systems, such as
146 .IR /etc/utmp ,
147 .IR /var/adm/utmp ,
148 .IR /var/run/utmp .
150 The glibc2 implementation of this function reads the file
151 .BR _PATH_TTYS ,
152 defined in
153 .I <ttyent.h>
154 as "/etc/ttys".
155 It returns 0 on error.
156 Since Linux systems do not usually have "/etc/ttys", it will
157 always return 0.
159 On BSD-like systems and Linux, the declaration of
160 .BR ttyslot ()
161 is provided by
162 .IR <unistd.h> .
163 On System V-like systems, the declaration is provided by
164 .IR <stdlib.h> .
165 Since glibc 2.24,
166 .I <stdlib.h>
167 also provides the declaration with the following
168 feature test macro definitions:
170 .in +4n
172 (_XOPEN_SOURCE >= 500 ||
173         (_XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED))
174     && ! (_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600)
178 Minix also has
179 .IR fttyslot ( fd ).
180 .\" .SH HISTORY
181 .\" .BR ttyslot ()
182 .\" appeared in UNIX V7.
183 .SH SEE ALSO
184 .BR getttyent (3),
185 .BR ttyname (3),
186 .BR utmp (5)