1 #include <stdlib.h>
2 #include <sys/ioctl.h>
3 #include <stdio.h>
4 #include <fcntl.h>
5 #include <errno.h>
6 #include "syscall.h"
7
posix_openpt(int flags)8 int posix_openpt(int flags)
9 {
10 return open("/dev/ptmx", flags);
11 }
12
grantpt(int fd)13 int grantpt(int fd)
14 {
15 return 0;
16 }
17
unlockpt(int fd)18 int unlockpt(int fd)
19 {
20 int unlock = 0;
21 return ioctl(fd, TIOCSPTLCK, &unlock);
22 }
23
__ptsname_r(int fd,char * buf,size_t len)24 int __ptsname_r(int fd, char *buf, size_t len)
25 {
26 int pty, err;
27 if (!buf) len = 0;
28 if ((err = __syscall(SYS_ioctl, fd, TIOCGPTN, &pty))) return -err;
29 if (snprintf(buf, len, "/dev/pts/%d", pty) >= len) return ERANGE;
30 return 0;
31 }
32
33 weak_alias(__ptsname_r, ptsname_r);
34