Kernel/LibC: Replace terminal syscalls with ioctls

isatty, tc{get,set}attr, tc{get,set}pgrp are now implemented as ioctls
instead of separate syscalls
This commit is contained in:
2026-05-15 16:38:36 +03:00
parent fe2c9f7d2d
commit 05c9f0640c
9 changed files with 114 additions and 160 deletions

View File

@@ -3,20 +3,11 @@
#include <errno.h>
#include <pthread.h>
#include <sys/ioctl.h>
#include <sys/syscall.h>
#include <termios.h>
#include <unistd.h>
speed_t cfgetispeed(const struct termios* termios)
{
return termios->c_ispeed;
}
speed_t cfgetospeed(const struct termios* termios)
{
return termios->c_ospeed;
}
static bool is_valid_speed(speed_t speed)
{
switch (speed)
@@ -43,6 +34,16 @@ static bool is_valid_speed(speed_t speed)
}
}
speed_t cfgetispeed(const struct termios* termios)
{
return termios->c_ispeed;
}
speed_t cfgetospeed(const struct termios* termios)
{
return termios->c_ospeed;
}
int cfsetispeed(struct termios* termios, speed_t speed)
{
if (!is_valid_speed(speed))
@@ -87,18 +88,32 @@ int tcflush(int fd, int queue_selector)
int tcgetattr(int fildes, struct termios* termios)
{
return syscall(SYS_TCGETATTR, fildes, termios);
return ioctl(fildes, TCGETS, termios);
}
pid_t tcgetsid(int);
int tcsetattr(int fildes, int optional_actions, const struct termios* termios)
{
int ioctl_num;
switch (optional_actions)
{
case TCSANOW:
ioctl_num = TCSETS;
break;
case TCSADRAIN:
ioctl_num = TCSETSW;
break;
case TCSAFLUSH:
ioctl_num = TCSETSF;
break;
default:
errno = EINVAL;
return -1;
}
return ioctl(fildes, ioctl_num, termios);
}
int tcsendbreak(int fd, int duration)
{
dwarnln("FIXME: tcsendbreak({}, {})", fd, duration);
return -1;
}
int tcsetattr(int fildes, int optional_actions, const struct termios* termios)
{
return syscall(SYS_TCSETATTR, fildes, optional_actions, termios);
}