tty.c 965 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. /*
  10. * turn raw (no echo, etc.) on and off.
  11. * ptyfs is gone, so don't even try tcsetattr, etc.
  12. */
  13. #define _POSIX_SOURCE
  14. #define _RESEARCH_SOURCE
  15. #include <sys/types.h>
  16. #include <unistd.h>
  17. #include <fcntl.h>
  18. #include <libv.h>
  19. static int ctlfd = -1;
  20. /* fd is ignored */
  21. tty_echooff(int)
  22. {
  23. if(ctlfd >= 0)
  24. return 0;
  25. ctlfd = open("/dev/consctl", O_WRONLY);
  26. if(ctlfd < 0)
  27. return -1;
  28. write(ctlfd, "rawon", 5);
  29. return 0;
  30. }
  31. tty_echoon(int)
  32. {
  33. if(ctlfd >= 0){
  34. write(ctlfd, "rawoff", 6);
  35. close(ctlfd);
  36. ctlfd = -1;
  37. return 0;
  38. }
  39. return -1;
  40. }