OSDN Git Service

Import translated manuals from JM CVS Repository.
[linuxjm/jm.git] / manual / LDP_man-pages / original / man3 / ttyslot.3
1 .\" Copyright (C) 2002 Andries Brouwer <aeb@cwi.nl>
2 .\"
3 .\" Permission is granted to make and distribute verbatim copies of this
4 .\" manual provided the copyright notice and this permission notice are
5 .\" preserved on all copies.
6 .\"
7 .\" Permission is granted to copy and distribute modified versions of this
8 .\" manual under the conditions for verbatim copying, provided that the
9 .\" entire resulting derived work is distributed under the terms of a
10 .\" permission notice identical to this one.
11 .\"
12 .\" Since the Linux kernel and libraries are constantly changing, this
13 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
14 .\" responsibility for errors or omissions, or for damages resulting from
15 .\" the use of the information contained herein.  The author(s) may not
16 .\" have taken the same level of care in the production of this manual,
17 .\" which is licensed free of charge, as they might when working
18 .\" professionally.
19 .\"
20 .\" Formatted or processed versions of this manual, if unaccompanied by
21 .\" the source, must acknowledge the copyright and authors of this work.
22 .\"
23 .\" This replaces an earlier man page written by Walter Harms
24 .\" <walter.harms@informatik.uni-oldenburg.de>.
25 .\"
26 .TH TTYSLOT 3 2007-11-26 "GNU" "Linux Programmer's Manual"
27 .SH NAME
28 ttyslot \- find the slot of the current user's terminal in some file
29 .SH SYNOPSIS
30 .BR "#include <unistd.h>"       "    /* on BSD-like systems, and Linux */"
31 .br
32 .BR "#include <stdlib.h>"       "    /* on System V-like systems */"
33 .sp
34 .B "int ttyslot(void);"
35 .sp
36 .in -4n
37 Feature Test Macro Requirements for glibc (see
38 .BR feature_test_macros (7)):
39 .in
40 .sp
41 .ad l
42 .BR ttyslot ():
43 _BSD_SOURCE || (_XOPEN_SOURCE_EXTENDED && !\ _XOPEN_SOURCE\ >=\ 500)
44 .ad b
45 .SH DESCRIPTION
46 The legacy function
47 .BR ttyslot ()
48 returns the index of the current user's entry in some file.
49 .LP
50 Now "What file?" you ask.
51 Well, let's first look at some history.
52 .SS "Ancient History"
53 There used to be a file
54 .I /etc/ttys
55 in Unix V6, that was read by the
56 .BR init (8)
57 program to find out what to do with each terminal line.
58 Each line consisted of three characters.
59 The first character was either \(aq0\(aq or \(aq1\(aq,
60 where \(aq0\(aq meant "ignore".
61 The second character denoted the terminal: \(aq8\(aq stood for "/dev/tty8".
62 The third character was an argument to
63 .BR getty (8)
64 indicating the sequence of line speeds to try (\(aq\-\(aq was: start trying
65 110 baud).
66 Thus a typical line was "18\-".
67 A hang on some line was solved by changing the \(aq1\(aq to a \(aq0\(aq,
68 signaling init, changing back again, and signaling init again.
69 .LP
70 In Unix V7 the format was changed: here the second character
71 was the argument to
72 .BR getty (8)
73 indicating the sequence of line speeds to try (\(aq0\(aq was: cycle through
74 300-1200-150-110 baud; \(aq4\(aq was for the on-line console DECwriter)
75 while the rest of the line contained the name of the tty.
76 Thus a typical line was "14console".
77 .LP
78 Later systems have more elaborate syntax.
79 System V-like systems have
80 .I /etc/inittab
81 instead.
82 .SS "Ancient History (2)"
83 On the other hand, there is the file
84 .I /etc/utmp
85 listing the people currently logged in.
86 It is maintained by
87 .BR login (1).
88 It has a fixed size, and the appropriate index in the file was
89 determined by
90 .BR login (1)
91 using the
92 .BR ttyslot ()
93 call to find the number of the line in
94 .I /etc/ttys
95 (counting from 1).
96 .SS "The semantics of ttyslot"
97 Thus, the function
98 .BR ttyslot ()
99 returns the index of the controlling terminal of the calling process
100 in the file
101 .IR /etc/ttys ,
102 and that is (usually) the same as the index of the entry for the
103 current user in the file
104 .IR /etc/utmp .
105 BSD still has the
106 .I /etc/ttys
107 file, but System V-like systems do not, and hence cannot refer to it.
108 Thus, on such systems the documentation says that
109 .BR ttyslot ()
110 returns the current user's index in the user accounting data base.
111 .SH "RETURN VALUE"
112 If successful, this function returns the slot number.
113 On error (e.g., if none of the file descriptors 0, 1 or 2 is
114 associated with a terminal that occurs in this data base)
115 it returns 0 on Unix V6 and V7 and BSD-like systems,
116 but \-1 on System V-like systems.
117 .SH "CONFORMING TO"
118 SUSv1; marked as LEGACY in SUSv2; removed in POSIX.1-2001.
119 SUSv2 requires \-1 on error.
120 .SH NOTES
121 The utmp file is found various places on various systems, such as
122 .IR /etc/utmp ,
123 .IR /var/adm/utmp ,
124 .IR /var/run/utmp .
125 .LP
126 The glibc2 implementation of this function reads the file
127 .BR _PATH_TTYS ,
128 defined in
129 .I <ttyent.h>
130 as "/etc/ttys".
131 It returns 0 on error.
132 Since Linux systems do not usually have "/etc/ttys", it will
133 always return 0.
134 .LP
135 Minix also has
136 .IR fttyslot ( fd ).
137 .\" .SH HISTORY
138 .\" .BR ttyslot ()
139 .\" appeared in Unix V7.
140 .SH "SEE ALSO"
141 .BR getttyent (3),
142 .BR ttyname (3),
143 .BR utmp (5)