summaryrefslogtreecommitdiff
path: root/LibC/stdlib.cpp
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-01-15 06:30:19 +0100
committerAndreas Kling <awesomekling@gmail.com>2019-01-15 06:30:19 +0100
commit2f74c2f43009723c996f508f423eab3013b47792 (patch)
treec63ab495172eec96867ff28ffcffb5fbcbca0c98 /LibC/stdlib.cpp
parentecb4ab0943530794fb00a0a6e2a82e3e94e2f9a3 (diff)
downloadserenity-2f74c2f43009723c996f508f423eab3013b47792.zip
Add basic PTY support.
For now, there are four hard-coded PTYs: /dev/pt{m,s}[0123] Use this in the Terminal to open a pty pair and spawn a shell.
Diffstat (limited to 'LibC/stdlib.cpp')
-rw-r--r--LibC/stdlib.cpp15
1 files changed, 15 insertions, 0 deletions
diff --git a/LibC/stdlib.cpp b/LibC/stdlib.cpp
index deceb9f4e6..2c11843ef7 100644
--- a/LibC/stdlib.cpp
+++ b/LibC/stdlib.cpp
@@ -5,8 +5,10 @@
#include <string.h>
#include <alloca.h>
#include <assert.h>
+#include <errno.h>
#include <AK/Assertions.h>
#include <AK/Types.h>
+#include <Kernel/Syscall.h>
extern "C" {
@@ -215,6 +217,19 @@ long atol(const char* str)
return atoi(str);
}
+static char ptsname_buf[32];
+char* ptsname(int fd)
+{
+ if (ptsname_r(fd, ptsname_buf, sizeof(ptsname_buf)) < 0)
+ return nullptr;
+ return ptsname_buf;
+}
+
+int ptsname_r(int fd, char* buffer, size_t size)
+{
+ int rc = syscall(SC_ptsname_r, fd, buffer, size);
+ __RETURN_WITH_ERRNO(rc, rc, -1);
+}
static unsigned long s_next_rand = 1;