add ptsname_r (nonstandard) and split ptsname (standard) to separate file
[musl] / src / misc / pty.c
1 #include <stdlib.h>
2 #include <sys/ioctl.h>
3 #include <stdio.h>
4 #include <fcntl.h>
5 #include "libc.h"
6
7 int posix_openpt(int flags)
8 {
9         return open("/dev/ptmx", flags);
10 }
11
12 int grantpt(int fd)
13 {
14         return 0;
15 }
16
17 int unlockpt(int fd)
18 {
19         int unlock = 0;
20         return ioctl(fd, TIOCSPTLCK, &unlock);
21 }
22
23 int __ptsname_r(int fd, char *buf, size_t len)
24 {
25         int pty;
26         if (!buf) len = 0;
27         return -( ioctl (fd, TIOCGPTN, &pty) < 0
28                 || snprintf(buf, len, "/dev/pts/%d", pty) >= len );
29 }
30
31 weak_alias(__ptsname_r, ptsname_r);