master
 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
 8int posix_openpt(int flags)
 9{
10	int r = open("/dev/ptmx", flags);
11	if (r < 0 && errno == ENOSPC) errno = EAGAIN;
12	return r;
13}
14
15int grantpt(int fd)
16{
17	return 0;
18}
19
20int unlockpt(int fd)
21{
22	int unlock = 0;
23	return ioctl(fd, TIOCSPTLCK, &unlock);
24}
25
26int __ptsname_r(int fd, char *buf, size_t len)
27{
28	int pty, err;
29	if (!buf) len = 0;
30	if ((err = __syscall(SYS_ioctl, fd, TIOCGPTN, &pty))) return -err;
31	if (snprintf(buf, len, "/dev/pts/%d", pty) >= len) return ERANGE;
32	return 0;
33}
34
35weak_alias(__ptsname_r, ptsname_r);