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:
B0B50B75B110B134B150B200B300B600B1200B1800B2400B4800B9600B19200B38400B57600B115200B230400B460800B500000B576000B921600B1000000B1152000B1500000B2000000
These constants are additionally supported on the SPARC architecture π«
B76800B153600B307200B614400
And these constants are additionally supported on non-SPARC architectures π
B2500000B3000000B3500000B4000000
π¨ 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:
0β on success. slay π-1β on failure, and seterrnoto 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
- Copyright 2006-2015, Michael Kerrisk <mtk.manpages@gmail.com>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms