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 | |
parent | b6b81f697b38ef915a5dbf1311baba164822e917 (diff) | |
download | musl-a34ca6ead1f04283ebd04ffcc42f8dbc6995f2d1.tar.gz |
-rw-r--r-- | src/termios/cfgetospeed.c | 2 | ||||
-rw-r--r-- | src/termios/cfsetospeed.c | 10 | ||||
-rw-r--r-- | src/termios/cfsetspeed.c | 11 |
diff --git a/src/termios/cfgetospeed.c b/src/termios/cfgetospeed.c index 55fa6f55..de46a1d8 100644 --- a/src/termios/cfgetospeed.c +++ b/src/termios/cfgetospeed.c @@ -9,5 +9,5 @@ speed_t cfgetospeed(const struct termios *tio) speed_t cfgetispeed(const struct termios *tio) { - return cfgetospeed(tio); + return (tio->c_cflag & CIBAUD) / (CIBAUD/CBAUD); } diff --git a/src/termios/cfsetospeed.c b/src/termios/cfsetospeed.c index c9cbdd9d..3eab092a 100644 --- a/src/termios/cfsetospeed.c +++ b/src/termios/cfsetospeed.c @@ -16,7 +16,11 @@ int cfsetospeed(struct termios *tio, speed_t speed) int cfsetispeed(struct termios *tio, speed_t speed) { - return speed ? cfsetospeed(tio, speed) : 0; + if (speed & ~CBAUD) { + errno = EINVAL; + return -1; + } + tio->c_cflag &= ~CIBAUD; + tio->c_cflag |= speed * (CIBAUD/CBAUD); + return 0; } - -weak_alias(cfsetospeed, cfsetspeed); 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; +} |