|
NAME | LIBRARY | SYNOPSIS | DESCRIPTION | RETURN VALUE | ATTRIBUTES | VERSIONS | STANDARDS | HISTORY | SEE ALSO | COLOPHON |
|
|
|
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:
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 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(), │ Thread safety │ MT-Safe │
│ cfsetispeed(), cfsetospeed(), │ │ │
│ cfsetspeed() │ │ │
└──────────────────────────────────────┴───────────────┴─────────┘
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.
cfgetispeed()
cfgetospeed()
cfsetispeed()
cfsetospeed()
POSIX.1-2008.
cfsetspeed()
BSD.
cfgetispeed()
cfgetospeed()
cfsetispeed()
cfsetospeed()
POSIX.1-2001.
cfsetspeed()
4.4BSD.
speed_t(3type), termios(3type)
This page is part of the man-pages (Linux kernel and C library
user-space interface documentation) project. Information about
the project can be found at
⟨https://www.kernel.org/doc/man-pages/⟩. If you have a bug report
for this manual page, see
⟨https://git.kernel.org/pub/scm/docs/man-pages/man-pages.git/tree/CONTRIBUTING⟩.
This page was obtained from the tarball man-pages-6.19.tar.gz
fetched from
⟨https://mirrors.edge.kernel.org/pub/linux/docs/man-pages/⟩ on
2026-09-09. If you discover any rendering problems in this HTML
version of the page, or you believe there is a better or more up-
to-date source for the page, or you have corrections or
improvements to the information in this COLOPHON (which is not
part of the original manual page), send a mail to
man-pages@man7.org
Linux man-pages 6.19 2026-07-02 cfsetspeed(3)
Pages that refer to this page: signal-safety(7), termios(7)