diff options
author | Ian Moffett <ian@osmora.org> | 2024-03-07 17:28:00 -0500 |
---|---|---|
committer | Ian Moffett <ian@osmora.org> | 2024-03-07 17:28:32 -0500 |
commit | bd5969fc876a10b18613302db7087ef3c40f18e1 (patch) | |
tree | 7c2b8619afe902abf99570df2873fbdf40a4d1a1 /lib/mlibc/sysdeps/ironclad/generic/pty.cpp | |
parent | a95b38b1b92b172e6cc4e8e56a88a30cc65907b0 (diff) |
lib: Add mlibc
Signed-off-by: Ian Moffett <ian@osmora.org>
Diffstat (limited to 'lib/mlibc/sysdeps/ironclad/generic/pty.cpp')
-rw-r--r-- | lib/mlibc/sysdeps/ironclad/generic/pty.cpp | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/lib/mlibc/sysdeps/ironclad/generic/pty.cpp b/lib/mlibc/sysdeps/ironclad/generic/pty.cpp new file mode 100644 index 0000000..1626e4b --- /dev/null +++ b/lib/mlibc/sysdeps/ironclad/generic/pty.cpp @@ -0,0 +1,41 @@ +#include <asm/ioctls.h> +#include <bits/ensure.h> +#include <errno.h> +#include <fcntl.h> +#include <pty.h> +#include <stdio.h> +#include <unistd.h> +#include <stdlib.h> +#include <sys/syscall.h> +#include <sys/ioctl.h> + +int openpty(int *mfd, int *sfd, char *name, const struct termios *ios, const struct winsize *win) { + int ret; + int fds[2]; + SYSCALL1(SYSCALL_OPENPTY, fds); + if (errno) { + return -1; + } + *mfd = fds[0]; + *sfd = fds[1]; + + if (name != NULL) { + ret = ttyname_r(*mfd, name, (size_t)-1); + if (ret) { + return -1; + } + } + if (ios != NULL) { + ret = tcsetattr(*mfd, TCSANOW, ios); + if (ret) { + return -1; + } + } + if (win != NULL) { + ret = ioctl(*mfd, TIOCGWINSZ, win); + if (ret) { + return -1; + } + } + return ret; +} |