Skip to content

Commit

Permalink
options/posix: implement cf[sg]et[io]speed
Browse files Browse the repository at this point in the history
  • Loading branch information
no92 committed Nov 13, 2023
1 parent a9c8d14 commit 9863626
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions options/posix/generic/termios-stubs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,27 @@
#include <mlibc/posix-sysdeps.hpp>

speed_t cfgetispeed(const struct termios *tios) {
return tios->ibaud;
return tios->c_cflag & CBAUD;
}

speed_t cfgetospeed(const struct termios *tios) {
return tios->obaud;
return tios->c_cflag & CBAUD;
}
int cfsetispeed(struct termios *, speed_t) {
__ensure(!"Not implemented");
__builtin_unreachable();

int cfsetispeed(struct termios *termios, speed_t speed) {
return speed ? cfsetospeed(termios, speed) : 0;
}
int cfsetospeed(struct termios *, speed_t) {
__ensure(!"Not implemented");
__builtin_unreachable();

int cfsetospeed(struct termios *termios, speed_t speed) {
if(speed & ~CBAUD) {
errno = EINVAL;
return -1;
}

termios->c_cflag &= ~CBAUD;
termios->c_cflag |= speed;

return 0;
}

void cfmakeraw(struct termios *t) {
Expand Down

0 comments on commit 9863626

Please sign in to comment.