diff options
author | Rich Felker <dalias@aerifal.cx> | 2025-02-22 11:27:33 -0500 |
---|---|---|
committer | Rich Felker <dalias@aerifal.cx> | 2025-02-22 16:44:39 -0500 |
commit | a34ca6ead1f04283ebd04ffcc42f8dbc6995f2d1 (patch) | |
tree | b79aea82495e91038bb36720f8ea021336ef6327 /src/termios/cfsetspeed.c | |
parent | b6b81f697b38ef915a5dbf1311baba164822e917 (diff) | |
download | musl-a34ca6ead1f04283ebd04ffcc42f8dbc6995f2d1.tar.gz |
termios: fix input speed handling
traditionally, our cfsetispeed just set the output speed. this was not
conforming or reasonable behavior.
use of the input baud bits in termios c_cflag depends on kernel
support, which was added to linux along with TCSETS2 ioctl and
arbitrary-baud functionality sometime in the 2.6 series. with older
kernels, the separate input baud will not take, but this is the best
behavior we can hope for anyway, certainly better than wrongly
clobbering output baud setting.
the nonstandard cfsetspeed is now moved to a separate file, since it
no longer admits the weak alias implementation that made it
namespace-safe. it now sets the output speed, and on success, sets the
input speed to 0 (matched to output).
Diffstat (limited to 'src/termios/cfsetspeed.c')
-rw-r--r-- | src/termios/cfsetspeed.c | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/termios/cfsetspeed.c b/src/termios/cfsetspeed.c new file mode 100644 index 00000000..2c369db9 --- /dev/null +++ b/src/termios/cfsetspeed.c @@ -0,0 +1,11 @@ +#define _BSD_SOURCE +#include <termios.h> +#include <sys/ioctl.h> +#include <errno.h> + +int cfsetspeed(struct termios *tio, speed_t speed) +{ + int r = cfsetospeed(tio, speed); + if (!r) cfsetispeed(tio, 0); + return r; +} |