blob: b395d2c09e14f19bad0d7130de8c0a9c1cc14fd4 [file] [log] [blame]
Rich Felker0b44a032011-02-12 00:22:29 -05001#include <stdlib.h>
2#include <sys/ioctl.h>
3#include <stdio.h>
4#include <fcntl.h>
Rich Felkerc21a19d2012-06-20 15:11:27 -04005#include <errno.h>
Rich Felker750b7382011-04-13 08:35:32 -04006#include "libc.h"
Rich Felkerc21a19d2012-06-20 15:11:27 -04007#include "syscall.h"
Rich Felker0b44a032011-02-12 00:22:29 -05008
9int posix_openpt(int flags)
10{
11 return open("/dev/ptmx", flags);
12}
13
14int grantpt(int fd)
15{
16 return 0;
17}
18
19int unlockpt(int fd)
20{
21 int unlock = 0;
22 return ioctl(fd, TIOCSPTLCK, &unlock);
23}
24
Rich Felker750b7382011-04-13 08:35:32 -040025int __ptsname_r(int fd, char *buf, size_t len)
Rich Felker0b44a032011-02-12 00:22:29 -050026{
Rich Felkerc21a19d2012-06-20 15:11:27 -040027 int pty, err;
Rich Felker750b7382011-04-13 08:35:32 -040028 if (!buf) len = 0;
Rich Felker66193172014-03-17 00:25:23 -040029 if ((err = __syscall(SYS_ioctl, fd, TIOCGPTN, &pty))) return -err;
Rich Felkerc21a19d2012-06-20 15:11:27 -040030 if (snprintf(buf, len, "/dev/pts/%d", pty) >= len) return ERANGE;
31 return 0;
Rich Felker0b44a032011-02-12 00:22:29 -050032}
Rich Felker750b7382011-04-13 08:35:32 -040033
34weak_alias(__ptsname_r, ptsname_r);