From f2a087126c30c5c1525b8e6ba46af635e2fab2b4 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Wed, 5 Feb 2020 21:17:41 +0100 Subject: LibC: Add posix_openpt(), grantpt() and unlockpt() This makes getting a pseudoterminal pair a little bit more portable. Note that grantpt() and unlockpt() are currently no-ops, since we've already granted the pseudoterminal slave to the calling user. We also accept O_CLOEXEC to posix_openpt(), unlike some systems. :^) --- Libraries/LibC/stdlib.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'Libraries/LibC/stdlib.cpp') diff --git a/Libraries/LibC/stdlib.cpp b/Libraries/LibC/stdlib.cpp index 43b6e83ba7..925e8882e5 100644 --- a/Libraries/LibC/stdlib.cpp +++ b/Libraries/LibC/stdlib.cpp @@ -746,4 +746,26 @@ char* realpath(const char* pathname, char* buffer) errno = 0; return buffer; } + +int posix_openpt(int flags) +{ + if (flags & ~(O_RDWR | O_NOCTTY | O_CLOEXEC)) { + errno = EINVAL; + return -1; + } + + return open("/dev/ptmx", flags); +} + +int grantpt(int fd) +{ + (void)fd; + return 0; +} + +int unlockpt(int fd) +{ + (void)fd; + return 0; +} } -- cgit v1.2.3