My build of suckless st terminal
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.

41 lines
917 B

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