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.

43 lines
1011 B

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