TERMIOS(2)

NAME
termios, tcgetattr, tcsetattr, tcsendbreak, tcdrain, tcflush, tcflow, cfgetospeed, cfgetispeed, cfsetispeed, cfsetospeed - get and set terminal attributes, line control, get and set baud rate, get and set terminal foreground process group ID

SYNOPSIS
#include <termios.h>
#include <unistd.h>

int tcgetattr(int fd, struct termios *termios_p);

int tcsetattr(int fd, int optional_actions, struct termios *termios_p);

int tcsendbreak(int fd, int duration);

int tcdrain(int fd);

int tcflush(int fd, int queue_selector);

int tcflow(int fd, int action);

speed_t cfgetospeed(struct termios *termios_p);

int cfsetospeed(struct termios *termios_p, speed_t speed);

speed_t cfgetispeed(struct termios *termios_p);

int cfsetispeed(struct termios *termios_p, speed_t speed);

DESCRIPTION
The termios functions describe a general terminal interface that is provided to control asynchronous communications ports.

Many of the functions described here have a termios_p argument that is a pointer to a termios structure. This structure contains the following members:

    tcflag_t c_iflag;      /* input modes */
    tcflag_t c_oflag;      /* output modes */
    tcflag_t c_cflag;      /* control modes */
    tcflag_t c_lflag;      /* local modes */
    cc_t c_cc[NCCS];       /* control chars */

tcgetattr() gets the parameters associated with the object referred by fd and stores them in the termios structure referenced by termios_p. This function may be invoked from a background process; however, the terminal attributes may be subsequently changed by a foreground process.

tcsetattr() sets the parameters associated with the terminal (unless support is required from the underlying hardware that is not available) from the termios structure referred to by termios_p as follows:

TCSANOW
    the change occurs immediately.

TCSADRAIN
    the change occurs after all output written to fd has been transmitted. This function should be used when changing parameters that affect output.

TCSAFLUSH
    the change occurs after all output written to the object referred by fd has been transmitted, and all input that has been received but not read will be discarded before the change is made.

tcsendbreak() transmits a continuous stream of zero-valued bits for a specific duration, if the terminal is using asynchronous serial data transmission. If duration is zero, it transmits zero-valued bits for at least 0.25 seconds, and not more that 0.5 seconds. If duration is not zero, it sends zero-valued bits for duration*N seconds, where N is at least 0.25, and not more than 0.5.

If the terminal is not using asynchronous serial data transmission, tcsendbreak() returns without taking any action.

tcdrain() waits until all output written to the object referred to by fd has been transmitted.

tcflush() discards data written to the object referred to by fd but not transmitted, or data received but not read, depending on the value of queue_selector:

TCIFLUSH
    flushes data received but not read.

TCOFLUSH
    flushes data written but not transmitted.

TCIOFLUSH
    flushes both data received but not read, and data written but not transmitted.

The default on open of a terminal file is that neither its input nor its output is suspended.

tcflow() suspends transmission or reception of data on the object referred to by fd, depending on the value of actions:

TCOOFF
    suspends output.

TCOON
    restarts suspended output.

TCIOFF
    transmits a STOP character, which stops the terminal device from transmitting data to the system.

TCION
    transmits a START character, which starts the terminal device transmitting data to the system.

The baud rate functions are provided for getting and setting the values of the input and output baud rates in the termios structure. The effects on the terminal device described below do not become effective until tcsetattr() is successfully called.

The input and output baud rates are stored in the termios structure.

cfgetospeed() returns the output baud rate stored in the termios structure pointed to by termios_p.

cfsetospeed() sets the output baud rate stored in the termios structure pointed to by termios_p to speed. The zero baud rate, B0, is used to terminate the connection. If B0 is specified, the modem control lines shall no longer be asserted. Normally, this will disconnect the line.

If the input baud rate is set to zero, the input baud rate will be specified by the value of the output baud rate.

cfgetispeed() returns the input baud rate stored in the termios structure.

cfsetispeed() sets the input baud rate stored in the termios structure to speed.

RETURN VALUES

cfgetispeed() returns the input baud rate stored in the termios structure.

cfgetospeed() returns the output baud rate stored in the termios structure.

cfsetispeed() and cfsetospeed() return:

0   on success.

-1  on failure and sets errno to indicate the error.

All other functions return:

0   on success.

-1  on failure and set errno to indicate the error.