---
name: "cfsetospeed"
section: "3"
platform: "linux"
package: "man-pages"
version: "6.19-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux", "freebsd"]
url: "https://new.carta.tech/cfsetspeed"
---

# cfsetospeed(3)

get and set line speed

Part of [cfsetspeed(3)](/cfsetspeed/3.md).

## NAME

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

## LIBRARY

Standard C library (*libc*, *-lc*)

## SYNOPSIS

```
#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)](/feature_test_macros/7.md) \*/ **#include \<termios.h\>**

**int cfsetspeed(struct termios \****termios\_p***, speed\_t** *speed***);**

## DESCRIPTION

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)](/tcsetattr/3.md) 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)](/setserial/8.md); 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:

- **B0** **B50** **B75** **B110** **B134** **B150** **B200** **B300** **B600** **B1200** **B1800** **B2400** **B4800** **B9600** **B19200** **B38400** **B57600** **B115200** **B230400** **B460800** **B500000** **B576000** **B921600** **B1000000** **B1152000** **B1500000** **B2000000**

  These constants are additionally supported on the SPARC architecture:

- **B76800** **B153600** **B307200** **B614400**

  These constants are additionally supported on non-SPARC architectures:

- **B2500000** **B3000000** **B3500000** **B4000000**

  Due to differences between architectures, portable applications should check if a particular **B***nnn* 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 **B***nnn* constants is possible via the **TCSETS2** ioctl; see [**ioctl\_tty**(2)](/ioctl_tty/2.md).

**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 **B***nnn* 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.

## RETURN VALUE

**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.

## ATTRIBUTES

For an explanation of the terms used in this section, see [**attributes**(7)](/attributes/7.md).

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

## VERSIONS

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.

## STANDARDS

- **cfgetispeed**() **cfgetospeed**() **cfsetispeed**() **cfsetospeed**()

  POSIX.1-2008.

- **cfsetspeed**()

  BSD.

## HISTORY

- **cfgetispeed**() **cfgetospeed**() **cfsetispeed**() **cfsetospeed**()

  POSIX.1-2001.

- **cfsetspeed**()

  4\.4BSD.

## SEE ALSO

[**speed\_t**(3type)](/speed_t/3type.md), [**termios**(3type)](/termios/3type.md)
