Simple Terminal from SuckLess
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
975 B

  1. /* See LICENSE file for copyright and license details. */
  2. #include <sys/types.h>
  3. #include <sys/stat.h>
  4. #include <fcntl.h>
  5. #include <stdlib.h>
  6. #if !(_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600)
  7. #include <pty.h>
  8. #endif
  9. extern int ptm, pts;
  10. void
  11. getpty(void) {
  12. char *ptsdev;
  13. #if defined(_GNU_SOURCE)
  14. ptm = getpt();
  15. #elif _POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600
  16. ptm = posix_openpt(O_RDWR);
  17. #else
  18. ptm = open("/dev/ptmx", O_RDWR);
  19. if(ptm == -1)
  20. if(openpty(&ptm, &pts, NULL, NULL, NULL) == -1)
  21. eprintn("error, cannot open pty");
  22. #endif
  23. #if defined(_XOPEN_SOURCE)
  24. if(ptm != -1) {
  25. if(grantpt(ptm) == -1)
  26. eprintn("error, cannot grant access to pty");
  27. if(unlockpt(ptm) == -1)
  28. eprintn("error, cannot unlock pty");
  29. ptsdev = ptsname(ptm);
  30. if(!ptsdev)
  31. eprintn("error, slave pty name undefined");
  32. pts = open(ptsdev, O_RDWR);
  33. if(pts == -1)
  34. eprintn("error, cannot open slave pty");
  35. }
  36. else
  37. eprintn("error, cannot open pty");
  38. #endif
  39. }