xref: /freebsd-src/stand/kboot/libkboot/termios.c (revision 36ef238cb604c827c696e975281f63d90641005f)
1*36ef238cSWarner Losh /*
2*36ef238cSWarner Losh  * Copyright (c) 2005-2020 Rich Felker, et al.
3*36ef238cSWarner Losh  *
4*36ef238cSWarner Losh  * SPDX-License-Identifier: MIT
5*36ef238cSWarner Losh  *
6*36ef238cSWarner Losh  * Note: From the musl project, stripped down and repackaged with HOST_/host_ prepended
7*36ef238cSWarner Losh  */
8*36ef238cSWarner Losh 
9*36ef238cSWarner Losh #include <sys/types.h>
10*36ef238cSWarner Losh #include "termios.h"
11*36ef238cSWarner Losh #include "host_syscall.h"
12*36ef238cSWarner Losh 
13*36ef238cSWarner Losh int
host_tcgetattr(int fd,struct host_termios * tio)14*36ef238cSWarner Losh host_tcgetattr(int fd, struct host_termios *tio)
15*36ef238cSWarner Losh {
16*36ef238cSWarner Losh 	if (host_ioctl(fd, HOST_TCGETS, (uintptr_t)tio))
17*36ef238cSWarner Losh 		return -1;
18*36ef238cSWarner Losh 	return 0;
19*36ef238cSWarner Losh }
20*36ef238cSWarner Losh 
21*36ef238cSWarner Losh int
host_tcsetattr(int fd,int act,const struct host_termios * tio)22*36ef238cSWarner Losh host_tcsetattr(int fd, int act, const struct host_termios *tio)
23*36ef238cSWarner Losh {
24*36ef238cSWarner Losh 	if (act < 0 || act > 2) {
25*36ef238cSWarner Losh //		errno = EINVAL;	/* XXX ?? */
26*36ef238cSWarner Losh 		return -1;
27*36ef238cSWarner Losh 	}
28*36ef238cSWarner Losh 	return host_ioctl(fd, HOST_TCSETS+act, (uintptr_t)tio);
29*36ef238cSWarner Losh }
30*36ef238cSWarner Losh 
31*36ef238cSWarner Losh void
host_cfmakeraw(struct host_termios * t)32*36ef238cSWarner Losh host_cfmakeraw(struct host_termios *t)
33*36ef238cSWarner Losh {
34*36ef238cSWarner Losh 	t->c_iflag &= ~(HOST_IGNBRK | HOST_BRKINT | HOST_PARMRK | HOST_ISTRIP |
35*36ef238cSWarner Losh 	    HOST_INLCR | HOST_IGNCR | HOST_ICRNL | HOST_IXON);
36*36ef238cSWarner Losh 	t->c_oflag &= ~HOST_OPOST;
37*36ef238cSWarner Losh 	t->c_lflag &= ~(HOST_ECHO | HOST_ECHONL | HOST_ICANON | HOST_ISIG |
38*36ef238cSWarner Losh 	    HOST_IEXTEN);
39*36ef238cSWarner Losh 	t->c_cflag &= ~(HOST_CSIZE | HOST_PARENB);
40*36ef238cSWarner Losh 	t->c_cflag |= HOST_CS8;
41*36ef238cSWarner Losh 	t->c_cc[HOST_VMIN] = 1;
42*36ef238cSWarner Losh 	t->c_cc[HOST_VTIME] = 0;
43*36ef238cSWarner Losh }
44*36ef238cSWarner Losh 
host_cfsetospeed(struct host_termios * tio,host_speed_t speed)45*36ef238cSWarner Losh int host_cfsetospeed(struct host_termios *tio, host_speed_t speed)
46*36ef238cSWarner Losh {
47*36ef238cSWarner Losh 	if (speed & ~HOST_CBAUD) {
48*36ef238cSWarner Losh //		errno = EINVAL; /* XXX ? */
49*36ef238cSWarner Losh 		return -1;
50*36ef238cSWarner Losh 	}
51*36ef238cSWarner Losh 	tio->c_cflag &= ~HOST_CBAUD;
52*36ef238cSWarner Losh 	tio->c_cflag |= speed;
53*36ef238cSWarner Losh 	return 0;
54*36ef238cSWarner Losh }
55*36ef238cSWarner Losh 
host_cfsetispeed(struct host_termios * tio,host_speed_t speed)56*36ef238cSWarner Losh int host_cfsetispeed(struct host_termios *tio, host_speed_t speed)
57*36ef238cSWarner Losh {
58*36ef238cSWarner Losh 	return speed ? host_cfsetospeed(tio, speed) : 0;
59*36ef238cSWarner Losh }
60*36ef238cSWarner Losh 
61*36ef238cSWarner Losh int
host_cfsetspeed(struct host_termios * tio,host_speed_t speed)62*36ef238cSWarner Losh host_cfsetspeed(struct host_termios *tio, host_speed_t speed)
63*36ef238cSWarner Losh {
64*36ef238cSWarner Losh 	return host_cfsetospeed(tio, speed);	/* weak alias in musl */
65*36ef238cSWarner Losh }
66*36ef238cSWarner Losh 
67