'\" t .\" Copyright 2006-2015, Michael Kerrisk .\" Copyright, the authors of the Linux man-pages project .\" .\" SPDX-License-Identifier: GPL-2.0-or-later .\" .TH cfsetspeed 3 2026-07-02 "Linux man-pages 6.19" .SH NAME cfgetospeed, cfgetispeed, cfsetispeed, cfsetospeed, cfsetspeed \- get and set line speed .SH LIBRARY Standard C library .RI ( libc ,\~ \-lc ) .SH SYNOPSIS .nf .B #include .P .BI "speed_t cfgetispeed(const struct termios *" termios_p ); .BI "speed_t cfgetospeed(const struct termios *" termios_p ); .P .BI "int cfsetispeed(struct termios *" termios_p ", speed_t " speed ); .BI "int cfsetospeed(struct termios *" termios_p ", speed_t " speed ); .P .BR #define\~_DEFAULT_SOURCE " /* See feature_test_macros(7) */" .B #include .P .BI "int cfsetspeed(struct termios *" termios_p ", speed_t " speed ); .fi .SH DESCRIPTION The baud rate functions are provided for getting and setting the values of the input and output baud rates in the .I termios structure. The new values do not take effect until .BR tcsetattr (3) is successfully called. .P Setting the speed to .B B0 instructs the modem to "hang up". The actual bit rate corresponding to .B B38400 may be altered with .BR setserial (8); doing so is discouraged as it may break other applications later trying to use the same serial port. .P The input and output baud rates are stored in the .I termios structure. .P .BR cfgetospeed () returns the output baud rate stored in the .I termios structure pointed to by .IR termios_p . .P .BR cfsetospeed () sets the output baud rate stored in the .I termios structure pointed to by .I termios_p to .IR speed , which must be one of these constants: .RS .TP .B B0 .TQ .B B50 .TQ .B B75 .TQ .B B110 .TQ .B B134 .TQ .B B150 .TQ .B B200 .TQ .B B300 .TQ .B B600 .TQ .B B1200 .TQ .B B1800 .TQ .B B2400 .TQ .B B4800 .TQ .B B9600 .TQ .B B19200 .TQ .B B38400 .TQ .B B57600 .TQ .B B115200 .TQ .B B230400 .TQ .B B460800 .TQ .B B500000 .TQ .B B576000 .TQ .B B921600 .TQ .B B1000000 .TQ .B B1152000 .TQ .B B1500000 .TQ .B B2000000 .RE .P These constants are additionally supported on the SPARC architecture: .RS .TP .B B76800 .TQ .B B153600 .TQ .B B307200 .TQ .B B614400 .RE .P These constants are additionally supported on non-SPARC architectures: .RS .TP .B B2500000 .TQ .B B3000000 .TQ .B B3500000 .TQ .B B4000000 .RE .P Due to differences between architectures, portable applications should check if a particular .BI B nnn constant is defined prior to using it. .P The zero baud rate, .BR B0 , is used to terminate the connection. If .B B0 is specified, the modem control lines shall no longer be asserted. Normally, this will disconnect the line. .B CBAUDEX is a mask for the speeds beyond those defined in POSIX.1 (57600 and above). Thus, .BR B57600 " & " CBAUDEX is nonzero. .P Setting the baud rate to a value other than those defined by .BI B nnn constants is possible via the .B TCSETS2 ioctl; see .BR ioctl_tty (2). .P .BR cfgetispeed () returns the input baud rate stored in the .I termios structure. .P .BR cfsetispeed () sets the input baud rate stored in the .I termios structure to .IR speed , which must be specified as one of the .BI B nnn constants listed above for .BR cfsetospeed (). If the input baud rate is set to the literal constant .B 0 (not the symbolic constant .BR B0 ), the input baud rate will be equal to the output baud rate. .P .BR cfsetspeed () takes the same arguments as .BR cfsetispeed (), and sets both input and output speed. .SH RETURN VALUE .BR cfgetispeed () returns the input baud rate stored in the .I termios structure. .P .BR cfgetospeed () returns the output baud rate stored in the .I termios structure. .P All other functions return: .TP .B 0 on success. .TP .B \-1 on failure and set .I errno to indicate the error. .SH ATTRIBUTES For an explanation of the terms used in this section, see .BR attributes (7). .TS allbox; lbx lb lb l l l. Interface Attribute Value T{ .na .nh .BR cfgetispeed (), .BR cfgetospeed (), .BR cfsetispeed (), .BR cfsetospeed (), .BR cfsetspeed () T} Thread safety MT-Safe .TE .SH VERSIONS UNIX\ V7 and several later systems have a list of baud rates where after the values .B B0 through .B B9600 one finds the two constants .BR EXTA , .B EXTB ("External A" and "External B"). Many systems extend the list with much higher baud rates. .SH STANDARDS .TP .BR cfgetispeed () .TQ .BR cfgetospeed () .TQ .BR cfsetispeed () .TQ .BR cfsetospeed () POSIX.1-2008. .TP .BR cfsetspeed () BSD. .SH HISTORY .TP .BR cfgetispeed () .TQ .BR cfgetospeed () .TQ .BR cfsetispeed () .TQ .BR cfsetospeed () POSIX.1-2001. .TP .BR cfsetspeed () 4.4BSD. .SH SEE ALSO .BR speed_t (3type), .BR termios (3type)