2024-08-05 01:48:24 +03:00
|
|
|
#include <BAN/Assert.h>
|
|
|
|
#include <BAN/Debug.h>
|
|
|
|
|
2024-07-30 11:10:43 +03:00
|
|
|
#include <errno.h>
|
2023-05-16 19:22:10 +03:00
|
|
|
#include <sys/syscall.h>
|
|
|
|
#include <termios.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
2024-07-30 11:10:43 +03:00
|
|
|
speed_t cfgetispeed(const struct termios* termios)
|
|
|
|
{
|
|
|
|
return termios->c_ispeed;
|
|
|
|
}
|
2023-05-16 19:22:10 +03:00
|
|
|
|
2024-07-30 11:10:43 +03:00
|
|
|
speed_t cfgetospeed(const struct termios* termios)
|
|
|
|
{
|
|
|
|
return termios->c_ospeed;
|
|
|
|
}
|
2023-05-16 19:22:10 +03:00
|
|
|
|
2024-07-30 11:10:43 +03:00
|
|
|
static bool is_valid_speed(speed_t speed)
|
|
|
|
{
|
|
|
|
switch (speed)
|
|
|
|
{
|
|
|
|
case B0:
|
|
|
|
case B50:
|
|
|
|
case B75:
|
|
|
|
case B110:
|
|
|
|
case B134:
|
|
|
|
case B150:
|
|
|
|
case B200:
|
|
|
|
case B300:
|
|
|
|
case B600:
|
|
|
|
case B1200:
|
|
|
|
case B1800:
|
|
|
|
case B2400:
|
|
|
|
case B4800:
|
|
|
|
case B9600:
|
|
|
|
case B19200:
|
|
|
|
case B38400:
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2023-05-16 19:22:10 +03:00
|
|
|
|
2024-07-30 11:10:43 +03:00
|
|
|
int cfsetispeed(struct termios* termios, speed_t speed)
|
|
|
|
{
|
|
|
|
if (!is_valid_speed(speed))
|
|
|
|
{
|
|
|
|
errno = EINVAL;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
termios->c_ispeed = speed;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int cfsetospeed(struct termios* termios, speed_t speed)
|
|
|
|
{
|
|
|
|
if (!is_valid_speed(speed))
|
|
|
|
{
|
|
|
|
errno = EINVAL;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
termios->c_ospeed = speed;
|
|
|
|
return 0;
|
|
|
|
}
|
2023-05-16 19:22:10 +03:00
|
|
|
|
|
|
|
int tcdrain(int);
|
|
|
|
|
|
|
|
int tcflow(int, int);
|
|
|
|
|
2024-08-05 01:48:24 +03:00
|
|
|
int tcflush(int fd, int queue_selector)
|
|
|
|
{
|
|
|
|
dwarnln("FIXME: tcflush({}, {})", fd, queue_selector);
|
2024-08-09 17:03:21 +03:00
|
|
|
return 0;
|
2024-08-05 01:48:24 +03:00
|
|
|
}
|
2023-05-16 19:22:10 +03:00
|
|
|
|
2024-07-30 11:10:43 +03:00
|
|
|
int tcgetattr(int fildes, struct termios* termios)
|
2023-05-16 19:22:10 +03:00
|
|
|
{
|
2024-07-30 11:10:43 +03:00
|
|
|
return syscall(SYS_TCGETATTR, fildes, termios);
|
2023-05-16 19:22:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
pid_t tcgetsid(int);
|
|
|
|
|
|
|
|
int tcsendbreak(int, int);
|
|
|
|
|
2024-07-30 11:10:43 +03:00
|
|
|
int tcsetattr(int fildes, int optional_actions, const struct termios* termios)
|
2023-05-16 19:22:10 +03:00
|
|
|
{
|
2024-07-30 11:10:43 +03:00
|
|
|
return syscall(SYS_TCSETATTR, fildes, optional_actions, termios);
|
2023-05-16 19:22:10 +03:00
|
|
|
}
|