1ttyslot(3)                 Library Functions Manual                 ttyslot(3)
2
3
4

NAME

6       ttyslot - find the slot of the current user's terminal in some file
7

LIBRARY

9       Standard C library (libc, -lc)
10

SYNOPSIS

12       #include <unistd.h>       /* See NOTES */
13
14       int ttyslot(void);
15
16   Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
17
18       ttyslot():
19           Since glibc 2.24:
20               _DEFAULT_SOURCE
21           From glibc 2.20 to glibc 2.23:
22               _DEFAULT_SOURCE || (_XOPEN_SOURCE && _XOPEN_SOURCE < 500)
23           glibc 2.19 and earlier:
24               _BSD_SOURCE || (_XOPEN_SOURCE && _XOPEN_SOURCE < 500)
25

DESCRIPTION

27       The  legacy  function ttyslot() returns the index of the current user's
28       entry in some file.
29
30       Now "What file?" you ask.  Well, let's first look at some history.
31
32   Ancient history
33       There used to be a file /etc/ttys in UNIX V6,  that  was  read  by  the
34       init(1)  program  to find out what to do with each terminal line.  Each
35       line consisted of three characters.  The first character was either '0'
36       or  '1',  where  '0'  meant "ignore".  The second character denoted the
37       terminal: '8' stood for "/dev/tty8".  The third character was an  argu‐
38       ment  to  getty(8)  indicating  the sequence of line speeds to try ('-'
39       was: start trying 110 baud).  Thus a typical line was "18-".  A hang on
40       some  line  was  solved  by  changing the '1' to a '0', signaling init,
41       changing back again, and signaling init again.
42
43       In UNIX V7 the format was changed: here the second  character  was  the
44       argument to getty(8) indicating the sequence of line speeds to try ('0'
45       was: cycle through 300-1200-150-110 baud; '4' was for the on-line  con‐
46       sole  DECwriter)  while  the rest of the line contained the name of the
47       tty.  Thus a typical line was "14console".
48
49       Later systems have more elaborate syntax.  System V-like  systems  have
50       /etc/inittab instead.
51
52   Ancient history (2)
53       On  the other hand, there is the file /etc/utmp listing the people cur‐
54       rently logged in.  It is maintained by login(1).  It has a fixed  size,
55       and  the appropriate index in the file was determined by login(1) using
56       the ttyslot() call to find the number of the line in /etc/ttys  (count‐
57       ing from 1).
58
59   The semantics of ttyslot
60       Thus,  the function ttyslot() returns the index of the controlling ter‐
61       minal of the calling process in the file /etc/ttys, and that  is  (usu‐
62       ally)  the  same  as the index of the entry for the current user in the
63       file /etc/utmp.  BSD still has the /etc/ttys file,  but  System  V-like
64       systems  do  not,  and hence cannot refer to it.  Thus, on such systems
65       the documentation says that ttyslot() returns the current user's  index
66       in the user accounting data base.
67

RETURN VALUE

69       If  successful, this function returns the slot number.  On error (e.g.,
70       if none of the file descriptors 0, 1, or 2 is associated with a  termi‐
71       nal  that  occurs in this data base) it returns 0 on UNIX V6 and V7 and
72       BSD-like systems, but -1 on System V-like systems.
73

ATTRIBUTES

75       For an  explanation  of  the  terms  used  in  this  section,  see  at‐
76       tributes(7).
77
78       ┌──────────────────────────────────────────┬───────────────┬───────────┐
79Interface                                 Attribute     Value     
80       ├──────────────────────────────────────────┼───────────────┼───────────┤
81ttyslot()                                 │ Thread safety │ MT-Unsafe │
82       └──────────────────────────────────────────┴───────────────┴───────────┘
83

VERSIONS

85       The  utmp  file  is found in various places on various systems, such as
86       /etc/utmp, /var/adm/utmp, /var/run/utmp.
87

STANDARDS

89       None.
90

HISTORY

92       SUSv1; marked as LEGACY  in  SUSv2;  removed  in  POSIX.1-2001.   SUSv2
93       requires -1 on error.
94
95       The  glibc2  implementation of this function reads the file _PATH_TTYS,
96       defined in <ttyent.h> as "/etc/ttys".  It returns 0  on  error.   Since
97       Linux systems do not usually have "/etc/ttys", it will always return 0.
98
99       On BSD-like systems and Linux, the declaration of ttyslot() is provided
100       by <unistd.h>.  On System V-like systems, the declaration  is  provided
101       by   <stdlib.h>.   Since  glibc  2.24,  <stdlib.h>  also  provides  the
102       declaration with the following feature test macro definitions:
103
104           (_XOPEN_SOURCE >= 500 ||
105                   (_XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED))
106               && ! (_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600)
107
108       Minix also has fttyslot(fd).
109

SEE ALSO

111       getttyent(3), ttyname(3), utmp(5)
112
113
114
115Linux man-pages 6.05              2023-07-20                        ttyslot(3)
Impressum