freebsd-nq/stand/kboot/termios.c
Warner Losh 963037786f kboot: implement stripped down termios
Implement a stripped down termios, obtained from various files in musl
and HOST_ or host_ prepended to most things and a few unavoidable style
tweaks. Only implements the bits of termios we need for the boot loader:
put the terminal into raw mode, restore terminal settings and speed
stuff.

Sponsored by:		Netflix
2022-07-28 15:35:42 -06:00

67 lines
1.4 KiB
C

/*
* Copyright (c) 2005-2020 Rich Felker, et al.
*
* SPDX-License-Identifier: MIT
*
* Note: From the musl project, stripped down and repackaged with HOST_/host_ prepended
*/
#include <sys/types.h>
#include "termios.h"
#include "host_syscall.h"
int
host_tcgetattr(int fd, struct host_termios *tio)
{
if (host_ioctl(fd, HOST_TCGETS, (uintptr_t)tio))
return -1;
return 0;
}
int
host_tcsetattr(int fd, int act, const struct host_termios *tio)
{
if (act < 0 || act > 2) {
// errno = EINVAL; /* XXX ?? */
return -1;
}
return host_ioctl(fd, HOST_TCSETS+act, (uintptr_t)tio);
}
void
host_cfmakeraw(struct host_termios *t)
{
t->c_iflag &= ~(HOST_IGNBRK | HOST_BRKINT | HOST_PARMRK | HOST_ISTRIP |
HOST_INLCR | HOST_IGNCR | HOST_ICRNL | HOST_IXON);
t->c_oflag &= ~HOST_OPOST;
t->c_lflag &= ~(HOST_ECHO | HOST_ECHONL | HOST_ICANON | HOST_ISIG |
HOST_IEXTEN);
t->c_cflag &= ~(HOST_CSIZE | HOST_PARENB);
t->c_cflag |= HOST_CS8;
t->c_cc[HOST_VMIN] = 1;
t->c_cc[HOST_VTIME] = 0;
}
int host_cfsetospeed(struct host_termios *tio, host_speed_t speed)
{
if (speed & ~HOST_CBAUD) {
// errno = EINVAL; /* XXX ? */
return -1;
}
tio->c_cflag &= ~HOST_CBAUD;
tio->c_cflag |= speed;
return 0;
}
int host_cfsetispeed(struct host_termios *tio, host_speed_t speed)
{
return speed ? host_cfsetospeed(tio, speed) : 0;
}
int
host_cfsetspeed(struct host_termios *tio, host_speed_t speed)
{
return host_cfsetospeed(tio, speed); /* weak alias in musl */
}