1
0

pty.c 595 B

12345678910111213141516171819202122232425262728293031323334
  1. #include <stdlib.h>
  2. #include <sys/ioctl.h>
  3. #include <stdio.h>
  4. #include <fcntl.h>
  5. #include <errno.h>
  6. #include "libc.h"
  7. #include "syscall.h"
  8. int posix_openpt(int flags)
  9. {
  10. return open("/dev/ptmx", flags);
  11. }
  12. int grantpt(int fd)
  13. {
  14. return 0;
  15. }
  16. int unlockpt(int fd)
  17. {
  18. int unlock = 0;
  19. return ioctl(fd, TIOCSPTLCK, &unlock);
  20. }
  21. int __ptsname_r(int fd, char *buf, size_t len)
  22. {
  23. int pty, err;
  24. if (!buf) len = 0;
  25. if ((err = __syscall(SYS_ioctl, fd, TIOCGPTN, &pty))) return -err;
  26. if (snprintf(buf, len, "/dev/pts/%d", pty) >= len) return ERANGE;
  27. return 0;
  28. }
  29. weak_alias(__ptsname_r, ptsname_r);