libc: Add pseudoterminal-related functions
This commit is contained in:
parent
29a341d8f3
commit
75ea81bfbc
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user