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