Set and get the terminal baud rate.
#include <sys/str_tty.h>
int get_speed (FileDescriptor) int FileDescriptor;
int set_speed (FileDescriptor, Speed) int FileDescriptor; int Speed;
int reset_speed (FileDescriptor) int FileDescriptor;
The baud rate functions set_speed subroutine and get_speed subroutine are provided top allow the user applications to program any value of the baud rate that is supported by the asynchronous adapter, but that cannot be expressed using the termios subroutines cfsetospeed, cfsetispeed, cfgetospeed, and cfsgetispeed. Those subroutines are indeed limited to the set values {BO, B50, ..., B38400} described in <termios.h>.
Interaction with the termios Baud flags:
If the terminal's device driver supports these subroutines, it has two interfaces for baud rate manipulation.
normal mode: This is the default mode, in which a termios supported speed is in use.
speed-extended mode: This mode is entered either by calling set_speed subroutine a non-termios supported speed at the configuration of the line.
In this mode, all the calls to tcgetattr subroutine or TCGETS ioctl subroutine will have B50 in the returned termios structure.
If tcsetatt subroutine or TCSETS, TCSETAF, or TCSETAW ioctl subroutines is called and attempt to set B50, the actual baud rate is not changed. If is attempts to set any other termios-supported speed, the driver will switch back to the normal mode and the requested baud rate is set. Calling reset_speed subroutine is another way to switch back to the normal mode.
FileDescriptor | Specifies an open file descriptor. |
Speed | The integer value of the requested speed. |
Upon successful completion, set_speed and reset_speed return a value of 0, and get_speed returns a positive integer specifying the current speed of the line. Otherwise, a value of -1 is returned and the errno global variable is set to indicate the error.
Plus all the errno codes that may be set in case of failure in an ioctl subroutine issued to a streams based tty.
cfgetospeed, cfsetospeed, cfgetispeed, or cfsetispeed subroutines.