]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/ttyslot.3
man3/t-v.3: srcfix: Use a single-font-style macro for a single argument
[thirdparty/man-pages.git] / man3 / ttyslot.3
CommitLineData
fea681da
MK
1.\" Copyright (C) 2002 Andries Brouwer <aeb@cwi.nl>
2.\"
93015253 3.\" %%%LICENSE_START(VERBATIM)
fea681da
MK
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.
c13182ef 12.\"
fea681da
MK
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.
c13182ef 20.\"
fea681da
MK
21.\" Formatted or processed versions of this manual, if unaccompanied by
22.\" the source, must acknowledge the copyright and authors of this work.
4b72fb64 23.\" %%%LICENSE_END
fea681da
MK
24.\"
25.\" This replaces an earlier man page written by Walter Harms
26.\" <walter.harms@informatik.uni-oldenburg.de>.
27.\"
4b8c67d9 28.TH TTYSLOT 3 2017-09-15 "GNU" "Linux Programmer's Manual"
fea681da
MK
29.SH NAME
30ttyslot \- find the slot of the current user's terminal in some file
31.SH SYNOPSIS
f8c8a903 32.BR "#include <unistd.h>" " /See NOTES */"
68e4db0a 33.PP
fea681da 34.B "int ttyslot(void);"
68e4db0a 35.PP
cc4615cc
MK
36.in -4n
37Feature Test Macro Requirements for glibc (see
38.BR feature_test_macros (7)):
39.in
68e4db0a 40.PP
cc4615cc
MK
41.ad l
42.BR ttyslot ():
f0644d82 43.RS 4
f30306c4
MK
44Since glibc 2.24:
45 _DEFAULT_SOURCE
46.br
47From glibc 2.20 to 2.23:
3f1873a8 48 _DEFAULT_SOURCE ||
2ca6d534 49 _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE\ <\ 500
f0644d82 50.br
b40ec4cb 51Glibc 2.19 and earlier:
3f1873a8 52 _BSD_SOURCE ||
2ca6d534 53 _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE\ <\ 500
f0644d82 54.RE
cc4615cc 55.ad b
fea681da
MK
56.SH DESCRIPTION
57The legacy function
58.BR ttyslot ()
59returns the index of the current user's entry in some file.
dd3568a1 60.PP
c13182ef
MK
61Now "What file?" you ask.
62Well, let's first look at some history.
73d8cece 63.SS Ancient history
fea681da
MK
64There used to be a file
65.I /etc/ttys
b4112efb 66in UNIX\ V6, that was read by the
e8906093 67.BR init (1)
fea681da
MK
68program to find out what to do with each terminal line.
69Each line consisted of three characters.
f81fb444
MK
70The first character was either \(aq0\(aq or \(aq1\(aq,
71where \(aq0\(aq meant "ignore".
72The second character denoted the terminal: \(aq8\(aq stood for "/dev/tty8".
fea681da 73The third character was an argument to
d80b8255 74.BR getty (8)
f81fb444 75indicating the sequence of line speeds to try (\(aq\-\(aq was: start trying
c13182ef
MK
76110 baud).
77Thus a typical line was "18\-".
f81fb444 78A hang on some line was solved by changing the \(aq1\(aq to a \(aq0\(aq,
d9bfdb9c 79signaling init, changing back again, and signaling init again.
dd3568a1 80.PP
b4112efb 81In UNIX\ V7 the format was changed: here the second character
fea681da 82was the argument to
d80b8255 83.BR getty (8)
f81fb444
MK
84indicating the sequence of line speeds to try (\(aq0\(aq was: cycle through
85300-1200-150-110 baud; \(aq4\(aq was for the on-line console DECwriter)
fea681da
MK
86while the rest of the line contained the name of the tty.
87Thus a typical line was "14console".
dd3568a1 88.PP
fea681da 89Later systems have more elaborate syntax.
80b50848 90System V-like systems have
fea681da
MK
91.I /etc/inittab
92instead.
73d8cece 93.SS Ancient history (2)
fea681da
MK
94On the other hand, there is the file
95.I /etc/utmp
c13182ef
MK
96listing the people currently logged in.
97It is maintained by
49ec013c 98.BR login (1).
fea681da
MK
99It has a fixed size, and the appropriate index in the file was
100determined by
49ec013c 101.BR login (1)
fea681da
MK
102using the
103.BR ttyslot ()
104call to find the number of the line in
0daa9e92 105.I /etc/ttys
fea681da 106(counting from 1).
73d8cece 107.SS The semantics of ttyslot
fea681da
MK
108Thus, the function
109.BR ttyslot ()
a1ffe9f5 110returns the index of the controlling terminal of the calling process
fea681da
MK
111in the file
112.IR /etc/ttys ,
113and that is (usually) the same as the index of the entry for the
114current user in the file
115.IR /etc/utmp .
116BSD still has the
117.I /etc/ttys
80b50848 118file, but System V-like systems do not, and hence cannot refer to it.
fea681da
MK
119Thus, on such systems the documentation says that
120.BR ttyslot ()
121returns the current user's index in the user accounting data base.
47297adb 122.SH RETURN VALUE
fea681da
MK
123If successful, this function returns the slot number.
124On error (e.g., if none of the file descriptors 0, 1 or 2 is
125associated with a terminal that occurs in this data base)
b4112efb 126it returns 0 on UNIX\ V6 and V7 and BSD-like systems,
80b50848 127but \-1 on System V-like systems.
be05dcc7 128.SH ATTRIBUTES
fad2b208
PH
129For an explanation of the terms used in this section, see
130.BR attributes (7).
131.TS
132allbox;
133lb lb lb
134l l l.
135Interface Attribute Value
136T{
be05dcc7 137.BR ttyslot ()
fad2b208
PH
138T} Thread safety MT-Unsafe
139.TE
47297adb 140.SH CONFORMING TO
39ed8b54 141SUSv1; marked as LEGACY in SUSv2; removed in POSIX.1-2001.
2b2581ee 142SUSv2 requires \-1 on error.
fea681da 143.SH NOTES
62dc68ae 144The utmp file is found in various places on various systems, such as
fea681da
MK
145.IR /etc/utmp ,
146.IR /var/adm/utmp ,
147.IR /var/run/utmp .
dd3568a1 148.PP
fea681da
MK
149The glibc2 implementation of this function reads the file
150.BR _PATH_TTYS ,
151defined in
152.I <ttyent.h>
c13182ef
MK
153as "/etc/ttys".
154It returns 0 on error.
fea681da
MK
155Since Linux systems do not usually have "/etc/ttys", it will
156always return 0.
f8c8a903
MK
157.PP
158On BSD-like systems and Linux, the declaration of
159.BR ttyslot ()
160is provided by
161.IR <unistd.h> .
c52ba260 162On System V-like systems, the declaration is provided by
f8c8a903
MK
163.IR <stdlib.h> .
164Since glibc 2.24,
d8a86e74 165.I <stdlib.h>
f8c8a903
MK
166also provides the declaration with the following
167feature test macro definitions:
168.PP
f8c8a903 169.in +4n
b8302363 170.EX
f8c8a903
MK
171(_XOPEN_SOURCE >= 500 ||
172 (_XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED))
173 && ! (_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600)
b8302363 174.EE
e646a1ba 175.in
f8c8a903 176.PP
fea681da
MK
177Minix also has
178.IR fttyslot ( fd ).
889829be
MK
179.\" .SH HISTORY
180.\" .BR ttyslot ()
008f1ecc 181.\" appeared in UNIX V7.
47297adb 182.SH SEE ALSO
fea681da
MK
183.BR getttyent (3),
184.BR ttyname (3),
185.BR utmp (5)