tcsetattr()

NAME

cfgetispeed(), cfsetispeed(), cfgetospeed(), cfsetospeed(), tcgetattr(), tcsetattr() - manipulate the termios structure

SYNOPSIS

#include <termios.h>

speed_t cfgetispeed (const struct termios *t) int cfsetispeed (struct termios *t, speed_t speed) speed_t cfgetospeed (const struct termios *t) int cfsetospeed (struct termios *t, speed_t speed) int tcgetattr (int fd, struct termios *t) int tcsetattr (int fd, int action, const struct termios *t)

DESCRIPTION

The tcgetattr(2) and tcsetattr(2) functions are provided for getting and setting the termios structure.

The cfgetispeed(3), cfsetispeed(3), cfgetospeed(3) and cfsetospeed(3) functions are provided for getting and setting the baud rate values in the termios structure. These functions set attributes for the terminal, but those attributes do not take effect, nor are all errors detected, until the tcsetattr(2) function is called. Certain values for baud rates set in the termios structure and passed to tcsetattr(2) have special meanings. These are discussed in the portion of the manual page that describes the tcsetattr(2) function.

GETTING AND SETTING THE BAUD RATE

The input and output baud rates are found in the termios structure. The unsigned integer speed_t is typedef'd in the include file <termios.h>. Use the symbolic values defined there, since the value of the integer does not necessarily correspond to the baud rate being represented. (For example, B9600 may not be 9600.)

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 19,200 baud
B300 300 baud B38400 38,400 baud

The cfgetispeed(3) function returns the input baud rate in the termios structure referenced by tp.

The cfsetispeed(3) function sets the input baud rate in the termios structure referenced by tp to speed.

The cfgetospeed(3) function returns the output baud rate in the termios structure referenced by tp.

The cfsetospeed(3) function sets the output baud rate in the termios structure referenced by tp to speed.

Upon successful completion, the functions cfsetispeed(3) and cfsetospeed(3) return a value of 0. Otherwise, a value of -1 is returned and the global variable errno is set to indicate the error.

GETTING AND SETTING THE TERMIOS STATE

This section describes the functions that are used to control the general terminal interface. Unless otherwise noted for a specific command, these functions are restricted from use by background processes. Attempts to perform these operations shall cause the process group to be sent a SIGTTOU signal. If the calling process is blocking or ignoring SIGTTOU signals, the process is allowed to perform the operation and the SIGTTOU signal is not sent.

In all the functions, although fd is an open file descriptor, the functions affect the underlying terminal file, not just the open file description associated with the particular file descriptor.

The tcgetattr(2) function copies the parameters associated with the terminal referenced by fd in the termios structure referenced by tp. This function is allowed from a background process, however, the terminal attributes may be subsequently changed by a foreground process.

The tcsetattr(2) function sets the parameters associated with the terminal from the termios structure referenced by tp. The action field is created by ORing the following values, as specified in the include file <termios.h>.

TCSANOW
The change occurs immediately.
TCSADRAIN
The change occurs after all output written to fd has been transmitted to the terminal. This value of action should be used when changing parameters that affect output.
TCSAFLUSH
The change occurs after all output written to fd has been transmitted to the terminal. Additionally, any input that has been received but not read is discarded.

The 0 baud rate is used to terminate the connection. If 0 is specified as the output speed to the function tcsetattr(2), modem control will no longer be asserted on the terminal, disconnecting the terminal.

If zero is specified as the input speed to the function tcsetattr(2), the input baud rate will be set to the same value as that specified by the output baud rate.

RETURN VALUES

If tcsetattr(2) is unable to make any of the requested changes, it returns -1 and sets errno. Otherwise, it makes all of the requested changes it can. If the specified input and output baud rates differ and are a combination that is not supported, neither baud rate is changed.

Upon successful completion, the functions tcgetattr(2) and tcsetattr(2) return a value of 0. Otherwise, they return -1 and the global variable errno is set to indicate the error.

ERRORS

The functions tcgetattr(2) and tcsetattr(2) can set errno to the following values:

[EBADF]
The fd argument to tcgetattr(2) or tcsetattr(2) was not a valid file descriptor.
[EINTR]
The tcsetattr(2) function was interrupted by a signal.
[EINVAL]
The action argument to the tcsetattr(2) function was not valid, or an attempt was made to change an attribute represented in the termios structure to an unsupported value.
[ENOTTY]
The file associated with the fd argument to tcgetattr(2) or tcsetattr(2) is not a terminal.

NOTES

As of this writing, setting (or getting) the baud rate for a console window is unimportant, since on single PCs there is no modulated phone line connecting the terminal and the subsystem.

SEE ALSO

tcsendbreak(2)

termios(4)