tty.c 559 B

12345678910111213141516171819202122232425262728293031323334353637
  1. /*
  2. * turn raw (no echo, etc.) on and off.
  3. * ptyfs is gone, so don't even try tcsetattr, etc.
  4. */
  5. #define _POSIX_SOURCE
  6. #define _RESEARCH_SOURCE
  7. #include <sys/types.h>
  8. #include <unistd.h>
  9. #include <fcntl.h>
  10. #include <libv.h>
  11. static int ctlfd = -1;
  12. /* fd is ignored */
  13. tty_echooff(int fd)
  14. {
  15. if(ctlfd >= 0)
  16. return 0;
  17. ctlfd = open("/dev/consctl", O_WRONLY);
  18. if(ctlfd < 0)
  19. return -1;
  20. write(ctlfd, "rawon", 5);
  21. return 0;
  22. }
  23. tty_echoon(int fd)
  24. {
  25. if(ctlfd >= 0){
  26. write(ctlfd, "rawoff", 6);
  27. close(ctlfd);
  28. ctlfd = -1;
  29. return 0;
  30. }
  31. return -1;
  32. }