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:
@@ -49,8 +49,14 @@ struct winsize
|
||||
unsigned short ws_xpixel; /* unused by kernel */
|
||||
unsigned short ws_ypixel; /* unused by kernel */
|
||||
};
|
||||
#define TIOCGWINSZ 50
|
||||
#define TIOCSWINSZ 51
|
||||
#define TIOCGWINSZ 50
|
||||
#define TIOCSWINSZ 51
|
||||
#define TCGETS 52
|
||||
#define TCSETS 53
|
||||
#define TCSETSW 54
|
||||
#define TCSETSF 55
|
||||
#define TIOCGPGRP 56
|
||||
#define TIOCSPGRP 57
|
||||
|
||||
struct snd_volume_info
|
||||
{
|
||||
|
||||
@@ -14,8 +14,6 @@ __BEGIN_DECLS
|
||||
O(SYS_SEEK, seek) \
|
||||
O(SYS_TELL, tell) \
|
||||
O(SYS_RENAMEAT, renameat) \
|
||||
O(SYS_TCGETATTR, tcgetattr) \
|
||||
O(SYS_TCSETATTR, tcsetattr) \
|
||||
O(SYS_FORK, fork) \
|
||||
O(SYS_EXEC, exec) \
|
||||
O(SYS_SLEEP, sleep) \
|
||||
@@ -39,8 +37,6 @@ __BEGIN_DECLS
|
||||
O(SYS_PIPE, pipe) \
|
||||
O(SYS_DUP2, dup2) \
|
||||
O(SYS_KILL, kill) \
|
||||
O(SYS_TCGETPGRP, tcgetpgrp) \
|
||||
O(SYS_TCSETPGRP, tcsetpgrp) \
|
||||
O(SYS_GET_PPID, getppid) \
|
||||
O(SYS_GET_PID, getpid) \
|
||||
O(SYS_GET_PGID, getpgid) \
|
||||
@@ -79,7 +75,6 @@ __BEGIN_DECLS
|
||||
O(SYS_SMO_CREATE, smo_create) \
|
||||
O(SYS_SMO_DELETE, smo_delete) \
|
||||
O(SYS_SMO_MAP, smo_map) \
|
||||
O(SYS_ISATTY, isatty) \
|
||||
O(SYS_GETSOCKNAME, getsockname) \
|
||||
O(SYS_GETPEERNAME, getpeername) \
|
||||
O(SYS_GETSOCKOPT, getsockopt) \
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/banan-os.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/syscall.h>
|
||||
#include <sys/time.h>
|
||||
@@ -349,7 +350,8 @@ int dup2(int fildes, int fildes2)
|
||||
|
||||
int isatty(int fildes)
|
||||
{
|
||||
return syscall(SYS_ISATTY, fildes) >= 0;
|
||||
struct termios termios;
|
||||
return tcgetattr(fildes, &termios) + 1;
|
||||
}
|
||||
|
||||
int gethostname(char* name, size_t namelen)
|
||||
@@ -838,7 +840,10 @@ pid_t getsid(pid_t pid)
|
||||
|
||||
int tcgetpgrp(int fildes)
|
||||
{
|
||||
return syscall(SYS_TCGETPGRP, fildes);
|
||||
pid_t pgrp;
|
||||
if (ioctl(fildes, TIOCGPGRP, &pgrp) == -1)
|
||||
return -1;
|
||||
return pgrp;
|
||||
}
|
||||
|
||||
int seteuid(uid_t uid)
|
||||
@@ -889,7 +894,7 @@ int setpgid(pid_t pid, pid_t pgid)
|
||||
|
||||
int tcsetpgrp(int fildes, pid_t pgid_id)
|
||||
{
|
||||
return syscall(SYS_TCSETPGRP, fildes, pgid_id);
|
||||
return ioctl(fildes, TIOCSPGRP, &pgid_id);
|
||||
}
|
||||
|
||||
char* getlogin(void)
|
||||
|
||||
Reference in New Issue
Block a user