IOCTL(2)
NAME
ioctl, stty, gtty − control device
SYNOPSIS
#include <sgtty.h>
ioctl(fildes, request, argp)
struct sgttyb *argp;
stty(fildes, argp)
struct sgttyb *argp;
gtty(fildes, argp)
struct sgttyb *argp;
DESCRIPTION
Ioctl performs a variety of functions on character special files (devices). The writeups of various devices in section 4 discuss how ioctl applies to them.
For certain status setting and status inquiries about terminal devices, the functions stty and gtty are equivalent to
ioctl(fildes, TIOCSETP, argp)
ioctl(fildes, TIOCGETP, argp)
respectively; see tty(4).
The following two calls, however, apply to any open file:
ioctl(fildes, FIOCLEX, NULL);
ioctl(fildes, FIONCLEX, NULL);
The first causes the file to be closed automatically during a successful exec operation; the second reverses the effect of the first.
RETURN VALUE
Zero is returned if the call was successful; −1 if the file descriptor does not refer to the kind of file for which it was intended.
DIAGNOSTICS
Ioctl will fail if one or more of the following is true:
[EBADF] Fildes is not a valid descriptor.
[EBADF] Carrier was lost on the terminal line.
[EFAULT] Argp points to an illegal address.
[ENOTTY] The specified request does not apply to the kind of object that the descriptor fildes references.
[ENXIO] An attempt was made to set an invalid line discipline.
[EPERM] The specified ioctl() function is only valid for the superuser (TIOCLOCAL, TIOCSMLB, TIOCCMLB).
RESTRICTIONS
Strictly speaking, since ioctl may be extended in different ways to devices with different properties, argp should have an open-ended declaration like
union { struct sgttyb ...; ... } *argp;
The important thing is that the size is fixed by ’struct sgttyb’.
SEE ALSO
ASSEMBLER
(ioctl = 54.)
sys ioctl; fildes; request; argp
(stty = 31.)
(file descriptor in r0)
stty; argp
(gtty = 32.)
(file descriptor in r0)
sys gtty; argp