cfsetspeed(3) Library Functions Manual cfsetspeed(3)

cfgetospeed, cfgetispeed, cfsetispeed, cfsetospeed, cfsetspeed - get and set line speed

Standard C library (libc-lc)

#include <termios.h>
speed_t cfgetispeed(const struct termios *termios_p);
speed_t cfgetospeed(const struct termios *termios_p);
int cfsetispeed(struct termios *termios_p, speed_t speed);
int cfsetospeed(struct termios *termios_p, speed_t speed);
#define _DEFAULT_SOURCE  /* See feature_test_macros(7) */
#include <termios.h>
int cfsetspeed(struct termios *termios_p, speed_t speed);

The baud rate functions are provided for getting and setting the values of the input and output baud rates in the termios structure. The new values do not take effect until tcsetattr(3) is successfully called.

Setting the speed to B0 instructs the modem to "hang up". The actual bit rate corresponding to B38400 may be altered with setserial(8); doing so is discouraged as it may break other applications later trying to use the same serial port.

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, which must be one of these constants:

These constants are additionally supported on the SPARC architecture:

These constants are additionally supported on non-SPARC architectures:

Due to differences between architectures, portable applications should check if a particular Bnnn constant is defined prior to using it.

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. CBAUDEX is a mask for the speeds beyond those defined in POSIX.1 (57600 and above). Thus, B57600 & CBAUDEX is nonzero.

Setting the baud rate to a value other than those defined by Bnnn constants is possible via the TCSETS2 ioctl; see ioctl_tty(2).

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

cfsetispeed() sets the input baud rate stored in the termios structure to speed, which must be specified as one of the Bnnn constants listed above for cfsetospeed(). If the input baud rate is set to the literal constant 0 (not the symbolic constant B0), the input baud rate will be equal to the output baud rate.

cfsetspeed() takes the same arguments as cfsetispeed(), and sets both input and output speed.

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

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

All other functions return:

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

For an explanation of the terms used in this section, see attributes(7).

Interface Attribute Value
cfgetispeed (), cfgetospeed (), cfsetispeed (), cfsetospeed (), cfsetspeed () Thread safety MT-Safe

UNIX V7 and several later systems have a list of baud rates where after the values B0 through B9600 one finds the two constants EXTA, EXTB ("External A" and "External B"). Many systems extend the list with much higher baud rates.

POSIX.1-2008.
BSD.

POSIX.1-2001.
4.4BSD.

speed_t(3type), termios(3type)

2026-07-02 Linux man-pages 6.19