2 * Copyright (c) 2005-2020 Rich Felker, et al.
4 * SPDX-License-Identifier: MIT
6 * Note: From the musl project, stripped down and repackaged with HOST_/host_ prepended
11 #include "host_syscall.h"
14 host_tcgetattr(int fd, struct host_termios *tio)
16 if (host_ioctl(fd, HOST_TCGETS, (uintptr_t)tio))
22 host_tcsetattr(int fd, int act, const struct host_termios *tio)
24 if (act < 0 || act > 2) {
25 // errno = EINVAL; /* XXX ?? */
28 return host_ioctl(fd, HOST_TCSETS+act, (uintptr_t)tio);
32 host_cfmakeraw(struct host_termios *t)
34 t->c_iflag &= ~(HOST_IGNBRK | HOST_BRKINT | HOST_PARMRK | HOST_ISTRIP |
35 HOST_INLCR | HOST_IGNCR | HOST_ICRNL | HOST_IXON);
36 t->c_oflag &= ~HOST_OPOST;
37 t->c_lflag &= ~(HOST_ECHO | HOST_ECHONL | HOST_ICANON | HOST_ISIG |
39 t->c_cflag &= ~(HOST_CSIZE | HOST_PARENB);
40 t->c_cflag |= HOST_CS8;
41 t->c_cc[HOST_VMIN] = 1;
42 t->c_cc[HOST_VTIME] = 0;
45 int host_cfsetospeed(struct host_termios *tio, host_speed_t speed)
47 if (speed & ~HOST_CBAUD) {
48 // errno = EINVAL; /* XXX ? */
51 tio->c_cflag &= ~HOST_CBAUD;
52 tio->c_cflag |= speed;
56 int host_cfsetispeed(struct host_termios *tio, host_speed_t speed)
58 return speed ? host_cfsetospeed(tio, speed) : 0;
62 host_cfsetspeed(struct host_termios *tio, host_speed_t speed)
64 return host_cfsetospeed(tio, speed); /* weak alias in musl */