a /dev and named
a /dev/tty Ns Em xx and for which an entry exists in the initialization file
a /etc/ttys (see .Xr ttys 5 ) , or for pseudo-terminal devices created in ptyfs and named
p The .Fn isatty function determines if the file descriptor .Fa fd refers to a valid terminal type device.
p The .Fn ttyname function gets the related device name of a file descriptor for which .Fn isatty is true. The .Fn ttyname_r is the reentrant version of the above, and it places the results in .Fa buf . If there is not enough space to place the results (indicated by .Fa len ), then it returns .Dv NULL .
p The .Fn ttyslot function fetches the current process' control terminal number from the .Xr ttys 5 file entry. If the terminal is a pseudo-terminal, and there is no special entry in the .Xr ttys 5 file for it, the slot number returned is 1 + (last slot number) + minor(tty). This will return a consistent and unique number for each pseudo-terminal device without requiring one to enumerate all of them in .Xr ttys 5 . .Sh RETURN VALUES The .Fn ttyname and .Fn ttyname_r functions return the NUL terminated name if the device is found and .Fn isatty is true; otherwise a .Dv NULL pointer is returned and .Va errno is set to indicate the error.
p The .Fn isatty function returns 1 if .Fa fd is associated with a terminal device; otherwise it returns 0 and .Va errno is set to indicate the error.
p The .Fn ttyslot function returns the unit number of the device file if found; otherwise the value zero is returned. .Sh FILES l -tag -width /etc/ttys -compact t Pa /dev/\(** t Pa /etc/ttys .El .Sh ERRORS The .Fn ttyname , .Fn ttyname_r , and .Fn isatty functions will fail if: l -tag -width Er t Bq Er EBADF The .Fa fd argument is not a valid file descriptor. t Bq Er ENOTTY The .Fa fd argument does not refer to a terminal device. .El The .Fn ttyname_r function will also fail if: l -tag -width Er t Bq Er ERANGE The buffer provided is not large enough to fit the result. .El .Sh SEE ALSO .Xr ioctl 2 , .Xr ttys 5 .Sh STANDARDS The .Fn ttyname and .Fn isatty functions conform to .St -p1003.1-90 . .Sh HISTORY A .Fn isatty , .Fn ttyname , and .Fn ttyslot function appeared in .At v7 . .Sh BUGS The .Fn ttyname function leaves its result in an internal static object and returns a pointer to that object. Subsequent calls to .Fn ttyname will modify the same object.