tty.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /* kernel/tty.c
  2. *
  3. * This file is part of evx.
  4. *
  5. * evx is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * evx is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with evx. If not, see <https://www.gnu.org/licenses/>
  17. */
  18. #include <kernel/init.h>
  19. #include <kernel/module.h>
  20. #include <kernel/tty.h>
  21. #include <kernel/mm.h>
  22. #include <sys/types.h>
  23. #include <lib/klist.h>
  24. struct klist_node ttys = KLIST_NODE_INIT(&ttys);
  25. int tty_register(struct tty *tty) {
  26. struct klist_node *n = kmalloc(sizeof(struct klist_node));
  27. n->data = tty;
  28. klist_add(&ttys, n);
  29. return 0;
  30. }
  31. int tty_write(struct tty *tty, char *s) {
  32. int err;
  33. while (*s++)
  34. if ((err = tty->putc(*s)))
  35. return err;
  36. return 0;
  37. }
  38. int tty_write_all(char *s) {
  39. struct tty *tty;
  40. struct klist_node *n;
  41. int err;
  42. while (*s++)
  43. for (n = ttys.next; n != &ttys; n = n->next) {
  44. tty = (struct tty *) n->data;
  45. if ((err = tty->putc(*s)))
  46. return err;
  47. }
  48. return 0;
  49. }