From 612eafea2c64b5e53ba3c47cde98d19341ab6dc7 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Mon, 29 Nov 2021 23:28:10 +0100 Subject: [PATCH] LibCore: Add syscall wrappers for tcgetattr() and tcsetattr() --- Userland/Libraries/LibCore/System.cpp | 16 ++++++++++++++++ Userland/Libraries/LibCore/System.h | 3 +++ 2 files changed, 19 insertions(+) diff --git a/Userland/Libraries/LibCore/System.cpp b/Userland/Libraries/LibCore/System.cpp index 17c6fd5cc0..a08d1bcff2 100644 --- a/Userland/Libraries/LibCore/System.cpp +++ b/Userland/Libraries/LibCore/System.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #define HANDLE_SYSCALL_RETURN_VALUE(syscall_name, rc, success_value) \ @@ -241,4 +242,19 @@ ErrorOr ioctl(int fd, unsigned request, ...) return {}; } +ErrorOr tcgetattr(int fd) +{ + struct termios ios = {}; + if (::tcgetattr(fd, &ios) < 0) + return Error::from_syscall("tcgetattr"sv, -errno); + return ios; +} + +ErrorOr tcsetattr(int fd, int optional_actions, struct termios const& ios) +{ + if (::tcsetattr(fd, optional_actions, &ios) < 0) + return Error::from_syscall("tcsetattr"sv, -errno); + return {}; +} + } diff --git a/Userland/Libraries/LibCore/System.h b/Userland/Libraries/LibCore/System.h index 2dc6665975..6f4fa49f7c 100644 --- a/Userland/Libraries/LibCore/System.h +++ b/Userland/Libraries/LibCore/System.h @@ -9,6 +9,7 @@ #include #include #include +#include namespace Core::System { @@ -37,5 +38,7 @@ ErrorOr dup2(int source_fd, int destination_fd); ErrorOr ptsname(int fd); ErrorOr gethostname(); ErrorOr ioctl(int fd, unsigned request, ...); +ErrorOr tcgetattr(int fd); +ErrorOr tcsetattr(int fd, int optional_actions, struct termios const&); }