Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 1 | #include <stdlib.h> |
| 2 | #include <sys/ioctl.h> |
| 3 | #include <stdio.h> |
| 4 | #include <fcntl.h> |
Rich Felker | c21a19d | 2012-06-20 15:11:27 -0400 | [diff] [blame] | 5 | #include <errno.h> |
Rich Felker | 750b738 | 2011-04-13 08:35:32 -0400 | [diff] [blame] | 6 | #include "libc.h" |
Rich Felker | c21a19d | 2012-06-20 15:11:27 -0400 | [diff] [blame] | 7 | #include "syscall.h" |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 8 | |
| 9 | int posix_openpt(int flags) |
| 10 | { |
| 11 | return open("/dev/ptmx", flags); |
| 12 | } |
| 13 | |
| 14 | int grantpt(int fd) |
| 15 | { |
| 16 | return 0; |
| 17 | } |
| 18 | |
| 19 | int unlockpt(int fd) |
| 20 | { |
| 21 | int unlock = 0; |
| 22 | return ioctl(fd, TIOCSPTLCK, &unlock); |
| 23 | } |
| 24 | |
Rich Felker | 750b738 | 2011-04-13 08:35:32 -0400 | [diff] [blame] | 25 | int __ptsname_r(int fd, char *buf, size_t len) |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 26 | { |
Rich Felker | c21a19d | 2012-06-20 15:11:27 -0400 | [diff] [blame] | 27 | int pty, err; |
Rich Felker | 750b738 | 2011-04-13 08:35:32 -0400 | [diff] [blame] | 28 | if (!buf) len = 0; |
Rich Felker | 6619317 | 2014-03-17 00:25:23 -0400 | [diff] [blame] | 29 | if ((err = __syscall(SYS_ioctl, fd, TIOCGPTN, &pty))) return -err; |
Rich Felker | c21a19d | 2012-06-20 15:11:27 -0400 | [diff] [blame] | 30 | if (snprintf(buf, len, "/dev/pts/%d", pty) >= len) return ERANGE; |
| 31 | return 0; |
Rich Felker | 0b44a03 | 2011-02-12 00:22:29 -0500 | [diff] [blame] | 32 | } |
Rich Felker | 750b738 | 2011-04-13 08:35:32 -0400 | [diff] [blame] | 33 | |
| 34 | weak_alias(__ptsname_r, ptsname_r); |