#include <termios.h> #include <unistd.h>
int tcgetattr(fd, termios_p) int fd; struct termios *termios_p;
int tcsetattr(fd, optional_actions, termios_p) int fd; int optional_actions; struct termios *termios_p;
int tcsendbreak(fd, duration) int fd; int duration;
int tcdrain(fd) int fd;
int tcflush(fd, queue_selector) int fd; int queue_selector;
int tcflow(fd, action) int fd; int action;
speed_t cfgetospeed(termios_p) struct termios *termios_p;
int cfsetospeed(termios_p, speed) struct termios *termios_p; speed_t speed;
speed_t cfgetispeed(termios_p) struct termios *termios_p;
int cfsetispeed(termios_p, speed) struct termios *termios_p; speed_t speed;
#include <sys/types.h> #include <termios.h>
The termios functions describe a general terminal interface that is provided to control asynchronous communications ports. A more detailed overview of the terminal interface can be found in termio.4 That section also describes an ioctl() interface that can be used to access the same functionality. However, the function interface described here is the preferred user interface.
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 */
These structure members are described in detail in termio.4
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:
The symbolic constants for the values of optional_actions are defined in <sys/termios.h>.
If the terminal is using asynchronous serial data transmission, tcsendbreak() transmits a continuous stream of zero-valued bits for a specific duration. 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:
The symbolic constants for the values of queue_selector and action are defined in termios.h.
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:
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.
The values shown in the table are supported.
The names in this table
are defined in
termios.h
Name Description Name Description ---------------------------------------------- B0 Hang up B600 600 baud B50 50 baud B1200 1200 baud B75 75 baud B1800 1800 baud B110 110 baud B2400 2400 baud B134 134.5 baud B4800 4800 baud B150 150 baud B9600 9600 baud B200 200 baud B19200 19200 baud B300 300 baud B38400 38400 baud
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.
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:
All other functions return:
tcsetattr() may set errno to:
An attempt was made to change an attribute represented in the termios structure to an unsupported value.
tcsendbreak() may set errno to:
tcdrain() may set errno to:
tcflush() may set errno to:
The queue_selector argument is not a proper value.
tcflow() may set errno to:
The action argument is not a proper value.
tcsetattr() may set errno to:
cfsetispeed() and cfsetospeed() may set errno to:
Created by unroff & hp-tools. © somebody (See intro for details). All Rights Reserved. Last modified 11/5/97