write.c 669 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /* $Source$
  2. * $State$
  3. * $Revision$
  4. */
  5. #include <stdlib.h>
  6. #include <errno.h>
  7. #include <unistd.h>
  8. #include <cpm.h>
  9. void _sys_write_tty(char c)
  10. {
  11. cpm_bc_register = CPM_BDOS_CONSOLE_OUTPUT;
  12. cpm_de_register = c;
  13. cpm_bdos();
  14. if (c == '\n')
  15. {
  16. cpm_bc_register = CPM_BDOS_CONSOLE_OUTPUT;
  17. cpm_de_register = '\r';
  18. cpm_bdos();
  19. }
  20. }
  21. int write(int fd, void* buffer, size_t count)
  22. {
  23. int i;
  24. char* p = buffer;
  25. /* We're only allowed to write to fd 0, 1 or 2. */
  26. if ((fd < 0) || (fd > 2))
  27. {
  28. errno = EBADF;
  29. return -1;
  30. }
  31. /* Write all data. */
  32. i = 0;
  33. while (i < count)
  34. {
  35. _sys_write_tty(*p++);
  36. i++;
  37. }
  38. /* No failures. */
  39. return count;
  40. }