stdio.c 668 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /*
  2. * Stdio replacement library
  3. * Maps common stdio functions to brfs functions
  4. */
  5. #define EOF -1
  6. // returns the current char at cursor within the opened file (EOF if end of file)
  7. // increments the cursor
  8. word fgetc(word fd, word filesize)
  9. {
  10. word cursor = fs_getcursor(fd);
  11. if (cursor == filesize)
  12. {
  13. return EOF;
  14. }
  15. char c;
  16. fs_read(fd, &c, 1);
  17. return c;
  18. }
  19. // write string to file
  20. word fputs(word fd, char* s)
  21. {
  22. fs_write(fd, s, strlen(s));
  23. return 1;
  24. }
  25. // write string to file
  26. word fputc(word fd, char c)
  27. {
  28. fs_write(fd, &c, 1);
  29. return 1;
  30. }
  31. word printf(char* s)
  32. {
  33. bdos_print(s);
  34. }
  35. word printd(word d)
  36. {
  37. bdos_printdec(d);
  38. }