initial check-in, version 0.5.0
[musl] / src / misc / pty.c
1 #include <stdlib.h>
2 #include <sys/ioctl.h>
3 #include <stdio.h>
4 #include <fcntl.h>
5
6 int posix_openpt(int flags)
7 {
8         return open("/dev/ptmx", flags);
9 }
10
11 int grantpt(int fd)
12 {
13         return 0;
14 }
15
16 int unlockpt(int fd)
17 {
18         int unlock = 0;
19         return ioctl(fd, TIOCSPTLCK, &unlock);
20 }
21
22 char *ptsname(int fd)
23 {
24         static char buf[9 + sizeof(int)*3 + 1];
25         char *s = buf+sizeof(buf)-1;
26         int pty;
27         if (ioctl (fd, TIOCGPTN, &pty))
28                 return NULL;
29         if (pty) for (; pty; pty/=10) *--s = '0' + pty%10;
30         else *--s = '0';
31         s -= 9;
32         s[0] = '/'; s[1] = 'd'; s[2] = 'e'; s[3] = 'v';
33         s[4] = '/'; s[5] = 'p'; s[6] = 't'; s[7] = 's'; s[8] = '/';
34         return s;
35 }