cfsetspeed(3)

πŸ’– cfsetspeed(3) β€” bestie edition πŸ’–

okay so like, this is cfsetspeed(3), a Library Functions Manual page, and it's all about baud rates β€” aka how fast your serial line is yapping. ngl it's giving "ancient Unix wisdom" but it's actually super useful, so let's get into it πŸ’…


✨ 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) */
#include <termios.h>

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

so basically you got five lil functions β€” two that get speeds, and three that set them 🫢 and note that cfsetspeed() is the ✨extra✨ one, it needs _DEFAULT_SOURCE defined first, so don't forget that or she simply will not show up to the party 😭


🌸 DESCRIPTION 🌸

The baud rate functions are here to get and set the values of the input and output baud rates inside the termios structure. But here's the thing bestie β€” the new values do not take effect until tcsetattr(3) is successfully called. So you're basically writing a lil note for later, not changing anything on the spot. πŸ™ˆ

Setting the speed to B0 tells the modem to "hang up". fr fr, it's the digital equivalent of walking out mid-conversation. πŸ’€

The actual bit rate that corresponds to B38400 may be altered with setserial(8). BUT β€” doing that is discouraged, because it may break other applications later trying to use the same serial port. so like, don't. πŸ™…

The input and output baud rates are stored in the termios structure. simple as that ✨

πŸ‘‘ the getters and setters

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, no substitutions:

  • 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

And these constants are additionally supported on non-SPARC architectures 🌈

  • B2500000
  • B3000000
  • B3500000
  • B4000000
🚨 bestie listen β€” due to differences between architectures, portable applications should check if a particular Bnnn constant is defined prior to using it. vibe check your constants first, always. 🫢

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. so yeah, that's the hang-up move again πŸ‘‹

CBAUDEX is a mask for the speeds beyond those defined in POSIX.1 (57600 and above). Thus, B57600 & CBAUDEX is nonzero. cute little bitwise flex πŸ’…

Setting the baud rate to a value other than those defined by the Bnnn constants is possible via the TCSETS2 ioctl; see ioctl_tty(2). so like, there's a back door if you need it πŸšͺ✨

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(). And here's the sneaky part β€” 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. it's giving "just match his energy" πŸ˜­βœ‹

cfsetspeed() takes the same arguments as cfsetispeed(), and sets both input and output speed. one function, two jobs, main character energy fr πŸ‘‘


⭐ 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:

  1. 0 β€” on success. slay πŸ’–
  2. -1 β€” on failure, and set errno to indicate the error. 😭

πŸ¦‹ ATTRIBUTES πŸ¦‹

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

  • Interface: cfgetispeed(), cfgetospeed(), cfsetispeed(), cfsetospeed(), cfsetspeed()
  • Attribute: Thread safety
  • Value: MT-Safe βœ…

so yeah, all five of them are thread-safe, we love a functional friend group 🫢


🌟 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"). Like, the OGs of baud rate lore. πŸ“œβœ¨

Many systems extend the list with much higher baud rates. they really said "let's go faster" πŸŽοΈπŸ’¨


πŸ“ STANDARDS πŸ“

  • cfgetispeed(), cfgetospeed(), cfsetispeed(), cfsetospeed() β€” POSIX.1-2008.
  • cfsetspeed() β€” BSD.

🧚 HISTORY 🧚

  • cfgetispeed(), cfgetospeed(), cfsetispeed(), cfsetospeed() β€” POSIX.1-2001.
  • cfsetspeed() β€” 4.4BSD.

so cfsetspeed() is out here with BSD heritage, a lil icon from the 4.4BSD era πŸ‘‘


πŸ‘€ SEE ALSO πŸ‘€


and that's the whole page bestie, no cap πŸ’œ

this was lovingly served to you by Linux man-pages 6.20, dated 2026-07-02, for cfsetspeed(3). go set some baud rates, you absolute legend πŸŽ€βœ¨πŸ’…

πŸ“¦ where this page comes from
  • arch rolling: man-pages 6.20-1 Β· BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
  • nixpkgs unstable: man-pages 6.20
  • πŸ“œ the page's license: GPL-2.0-or-later
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms