text: NAMEioctl_tty - ioctls for terminals and serial lines
  SYNOPSIS
  #include <termios.h>
  int ioctl(int fd, int cmd, ...);
  DESCRIPTIONThe
  - Argument: struct termios *argp
  - Equivalent to tcgetattr(fd, argp).
  - Get the current serial port settings.
  - TCSETS
  - Argument: const struct termios *argp
  - Equivalent to tcsetattr(fd, TCSANOW, argp).
  - Set the current serial port settings.
  - TCSETSW
  - Argument: const struct termios *argp
  - Equivalent to tcsetattr(fd, TCSADRAIN, argp).
  - Allow the output buffer to drain, and set the current serial port settings.
  - TCSETSF
  - Argument:The termios structure of a terminal can be locked. The lock is itself a termios structure, with nonzero bits or fields indicating a locked value.
  - TIOCGLCKTRMIOS
  - Argument: struct termios *argp
  - Gets the locking status of the termios structure of the terminal.
  - TIOCSLCKTRMIOS
  - Argument: const struct termios *argp
  - Sets the locking status of the termios structure of the terminal. Only a process with the CAP_SYS_ADMIN capability can do this.
  Get and set window sizeWindow
  - Argument: struct winsize *argp
  - Get window size.
  - TIOCSWINSZ
  - Argument:
  - Argument:
  - Argument: int arg
  - So-called "POSIX version" of TCSBRK. It treats nonzero arg as a time interval measured in deciseconds, and does nothing when the driver does not support breaks.
  - TIOCSBRK
  - Argument: void
  - Turn break on, that is, start sending zero bits.
  - TIOCCBRK
  - Argument: void
  - Turn break off, that is, stop sending zero bits.
  Software flow control
  - TCXONC
  - Argument: int arg
  Buffer count and flushing
  - FIONREAD
  - Argument: int *argp
  - Get the number of bytes in the input buffer.
  - TIOCINQ
  - Argument: int *argp
  - Same as FIONREAD.
  - TIOCOUTQ
  - Argument: int *argp
  - Get the number of bytes in the output buffer.
  - TCFLSH
  - Argument: int arg
  - Equivalent to tcflush(fd, arg).
  - See tcflush(3) for the argument values TCIFLUSH, TCOFLUSH, TCIOFLUSH.
  Faking input
  - TIOCSTI
  - Argument: const char *argp
  - Insert the given byte in the input queue.
  Redirecting console output
  - TIOCCONS
  - Argument: a process with the CAP_SYS_ADMIN capability may do this. If output was redirected already, then EBUSY is returned, but redirection can be stopped by using this ioctl with fd pointing at /dev/console or /dev/tty0.
  Controlling terminal
  - TIOCSCTTY
  - Argument: caller has the CAP_SYS_ADMIN capability and arg equals 1, in which case the terminal is stolen, and all processes that had it as controlling terminal lose it.
  - TIOCNOTTY
  - Argument:
  - Argument: pid_t *argp
  - When successful, equivalent to *argp = tcgetpgrp(fd).
  - Get the process group ID of the foreground process group on this terminal.
  - TIOCSPGRP
  - Argument: const pid_t *argp
  - Equivalent to tcsetpgrp(fd, *argp).
  - Set the foreground process group ID of this terminal.
  - TIOCGSID
  - Argument: pid_t *argp
  - Get the session ID of the given terminal. This fails with the error ENOTTY if the terminal is not a master pseudoterminal and not our controlling terminal. Strange.
  Exclusive mode
  - TIOCEXCL
  - Argument: void
  - Put the terminal into exclusive mode. No further open(2) operations on the terminal are permitted. (They fail with EBUSY, except for a process with the CAP_SYS_ADMIN capability.)
  - TIOCGEXCL
  - Argument: int *argp
  - (since Linux 3.8) If the terminal is currently in exclusive mode, place a nonzero value in the location pointed to by argp; otherwise, place zero in *argp.
  - TIOCNXCL
  - Argument: void
  - Disable exclusive mode.
  Line discipline
  - TIOCGETD
  - Argument: int *argp
  - Get the line discipline of the terminal.
  - TIOCSETD
  - Argument: const int *argp
  - Set the line discipline of the terminal.
  Pseudoterminal ioctls
  - TIOCPKT
  - Argument: ('\0') followed by data written on the slave side of the pseudoterminal. If the first byte is not TIOCPKT_DATA (0), it is an OR of one or more of the following bits:
  -
  - While packet
  - Argument: const int *argp
  - (since Linux 3.8) Return the current packet mode setting in the integer pointed to by argp.
  - TIOCSPTLCK
  - Argument: int *argp
  - Set (if *argp is nonzero) or remove (if *argp is zero) the lock on the pseudoterminal slave device. (See also unlockpt(3).)
  - TIOCGPTLCK
  - Argument: int *argp
  - (since Linux 3.8) Place the current lock state of the pseudoterminal slave device in the location pointed to by argp.
  - TIOCGPTPEER
  - Argument:
  - Argument: int *argp
  - Get the status of modem bits.
  - TIOCMSET
  - Argument: const int *argp
  - Set the status of modem bits.
  - TIOCMBIC
  - Argument: const int *argp
  - Clear the indicated modem bits.
  - TIOCMBIS
  - Argument: const int *argp
  - Set the indicated modem bits.
  The following bits are used by the above ioctls:
  - TIOCMIWAIT
  - Argument:
  - Argument:
  - Argument: int *argp
  - ("Get software carrier flag") Get the status of the CLOCAL flag in the c_cflag field of the termios structure.
  - TIOCSSOFTCAR
  - Argument:For the TIOCLINUX ioctl, see ioctl_console(2).
  Kernel debugging#include <linux/tty.h>
  - TIOCTTYGSTRUCT
  - Argument: struct tty_struct *argp
  - Get the tty_struct corresponding to fd. This command was removed in Linux 2.5.67.
  RETURN VALUEThe ioctl(2) system call returns 0 on success. On error, it returns -1 and sets errno to indicate the error.
  ERRORS
  - EINVAL
  - Invalid command parameter.
  - ENOIOCTLCMD
  - Unknown command.
  - ENOTTY
  - Inappropriate fd.
  - EPERM
  - Insufficient permission.
  EXAMPLESCheck set"); else puts("TIOCM_DTR is not set"); close(fd); }