Browse Source

LibCore: Add syscall wrappers for tcgetattr() and tcsetattr()

Andreas Kling 3 years ago
parent
commit
612eafea2c
2 changed files with 19 additions and 0 deletions
  1. 16 0
      Userland/Libraries/LibCore/System.cpp
  2. 3 0
      Userland/Libraries/LibCore/System.h

+ 16 - 0
Userland/Libraries/LibCore/System.cpp

@@ -13,6 +13,7 @@
 #include <sys/ioctl.h>
 #include <sys/ioctl.h>
 #include <sys/mman.h>
 #include <sys/mman.h>
 #include <sys/socket.h>
 #include <sys/socket.h>
+#include <termios.h>
 #include <unistd.h>
 #include <unistd.h>
 
 
 #define HANDLE_SYSCALL_RETURN_VALUE(syscall_name, rc, success_value) \
 #define HANDLE_SYSCALL_RETURN_VALUE(syscall_name, rc, success_value) \
@@ -241,4 +242,19 @@ ErrorOr<void> ioctl(int fd, unsigned request, ...)
     return {};
     return {};
 }
 }
 
 
+ErrorOr<struct termios> tcgetattr(int fd)
+{
+    struct termios ios = {};
+    if (::tcgetattr(fd, &ios) < 0)
+        return Error::from_syscall("tcgetattr"sv, -errno);
+    return ios;
+}
+
+ErrorOr<void> 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 {};
+}
+
 }
 }

+ 3 - 0
Userland/Libraries/LibCore/System.h

@@ -9,6 +9,7 @@
 #include <AK/Error.h>
 #include <AK/Error.h>
 #include <signal.h>
 #include <signal.h>
 #include <sys/stat.h>
 #include <sys/stat.h>
+#include <termios.h>
 
 
 namespace Core::System {
 namespace Core::System {
 
 
@@ -37,5 +38,7 @@ ErrorOr<int> dup2(int source_fd, int destination_fd);
 ErrorOr<String> ptsname(int fd);
 ErrorOr<String> ptsname(int fd);
 ErrorOr<String> gethostname();
 ErrorOr<String> gethostname();
 ErrorOr<void> ioctl(int fd, unsigned request, ...);
 ErrorOr<void> ioctl(int fd, unsigned request, ...);
+ErrorOr<struct termios> tcgetattr(int fd);
+ErrorOr<void> tcsetattr(int fd, int optional_actions, struct termios const&);
 
 
 }
 }