libc: Add pseudoterminal-related functions

This commit is contained in:
apio 2023-09-16 11:47:57 +02:00
parent d7db4e6147
commit 35633fc65f
Signed by: apio
GPG Key ID: B8A7D06E42258954
2 changed files with 42 additions and 0 deletions

View File

@ -148,6 +148,18 @@ extern "C"
/* Create a unique file from a template string whose last 6 bytes must be XXXXXX. */
int mkstemp(char* _template);
/* Create a new pseudoterminal pair. */
int posix_openpt(int flags);
/* Set the credentials of a pseudoterminal master. */
int grantpt(int fd);
/* Unlock a pseudoterminal master. */
int unlockpt(int fd);
/* Return the name of the slave associated with a pseudoterminal master. */
char* ptsname(int fd);
#ifdef __cplusplus
}
#endif

View File

@ -1,4 +1,5 @@
#include <bits/errno-return.h>
#include <bits/termios.h>
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
@ -7,8 +8,10 @@
#include <luna/Sort.h>
#include <luna/Utf8.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <sys/syscall.h>
#include <sys/wait.h>
@ -300,4 +303,31 @@ extern "C"
{
return strtod(str, nullptr);
}
int posix_openpt(int flags)
{
return open("/dev/ptmx", flags);
}
int grantpt(int)
{
return 0;
}
int unlockpt(int)
{
return 0;
}
char* ptsname(int fd)
{
static char buffer[4096];
int index;
if (ioctl(fd, TIOCGPTN, &index) < 0) return nullptr;
snprintf(buffer, sizeof(buffer), "/dev/pts/%d", index);
return buffer;
}
}