xref: /original-bsd/lib/libc/gen/ttyname.3 (revision 5000927f)
1.\" Copyright (c) 1991, 1993
2.\"	The Regents of the University of California.  All rights reserved.
3.\"
4.\" %sccs.include.redist.man%
5.\"
6.\"     @(#)ttyname.3	8.1 (Berkeley) 06/04/93
7.\"
8.Dd
9.Dt TTYNAME 3
10.Os
11.Sh NAME
12.Nm ttyname ,
13.Nm isatty ,
14.Nm ttyslot
15.Nd get name of associated terminal (tty) from file descriptor
16.Sh SYNOPSIS
17.Fd #include <unistd.h>
18.Ft char *
19.Fn ttyname "int fd"
20.Ft int
21.Fn isatty "int fd"
22.Ft int
23.Fn ttyslot
24.Sh DESCRIPTION
25These functions operate on the system file descriptors for terminal
26type devices. These descriptors are not related to the standard
27.Tn I/O
28.Dv FILE
29typedef, but refer to the special device files found in
30.Pa /dev
31and named
32.Pa /dev/tty Ns Em xx
33and for which an entry exists
34in the initialization file
35.Pa /etc/ttys.
36(See
37.Xr ttys 5 . )
38.Pp
39The
40.Fn isatty
41function
42determines if the file descriptor
43.Fa fd
44refers to a valid
45terminal type device.
46.Pp
47The
48.Fn ttyname
49function
50gets the related device name of
51a file descriptor for which
52.Fn isatty
53is true
54.Pp
55The
56.Fn ttyslot
57function
58fetches the current process' control terminal number from the
59.Xr ttys 5
60file entry.
61.Sh RETURN VALUES
62The
63.Fn ttyname
64function
65returns the null terminated name if the device is found and
66.Fn isatty
67is true; otherwise
68a
69.Dv NULL
70pointer is returned.
71.Pp
72The
73.Fn ttyslot
74function
75returns the unit number of the device file if found; otherwise
76the value zero is returned.
77.Sh FILES
78.Bl -tag -width /etc/ttys -compact
79.It Pa /dev/\(**
80.It Pa /etc/ttys
81.El
82.Sh SEE ALSO
83.Xr ioctl 2 ,
84.Xr ttys 5
85.Sh HISTORY
86A
87.Fn isatty ,
88.Fn ttyname ,
89and
90.Fn ttyslot
91function
92appeared in
93.At v7 .
94.Sh BUGS
95The
96.Fn ttyname
97function leaves its result in an internal static object and returns
98a pointer to that object. Subsequent calls to
99.Fn ttyname
100will modify the same object.
101