ioctl(2)
NAME
ioctl, stty, gtty − control device
SYNTAX
#include <sgtty.h>
int ioctl(fildes, request, argp)
int fildes, request;
int stty(fildes, argp)
int fildes;
int gtty(fildes, argp)
int fildes;
DESCRIPTION
The ioctl system call performs a variety of functions on character special files (devices). The appropriate manual pages in section(4) discuss how the ioctl call applies. The argp is specific to the device and request.
For certain status setting and status inquiries about terminal devices, the functions stty and gtty system calls are respectively equivalent to:
ioctl(fildes, TIOCSETP, argp)
ioctl(fildes, TIOCGETP, argp)
For further information, see tty(4).
The following two ioctl 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 call, while the second reverses the effect of the first.
RESTRICTIONS
Strictly speaking, because the ioctl call may be extended in different ways to devices with different properties, argp should have an open-ended declaration:
union { struct sgttyb... ; ... } *argp;
RETURN VALUE
If unsuccessful, returns a −1, and the global variable errno indicates the error code.
DIAGNOSTICS
The ioctl call will fail if:
[EBADF] The fildes argument is not a valid descriptor.
[EBADF] Carrier was lost on the terminal line.
[EFAULT] The argp argument 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 call is only valid for the superuser (TIOCLOCAL, TIOCSMLB, TIOCCMLB).
[EINTR] A signal was caught during the ioctl system call.
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