sys.c 745 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #include "sam.h"
  2. static int inerror=FALSE;
  3. /*
  4. * A reasonable interface to the system calls
  5. */
  6. void
  7. resetsys(void)
  8. {
  9. inerror = FALSE;
  10. }
  11. void
  12. syserror(char *a)
  13. {
  14. char buf[ERRMAX];
  15. if(!inerror){
  16. inerror=TRUE;
  17. errstr(buf, sizeof buf);
  18. dprint("%s: ", a);
  19. error_s(Eio, buf);
  20. }
  21. }
  22. int
  23. Read(int f, void *a, int n)
  24. {
  25. char buf[ERRMAX];
  26. if(read(f, (char *)a, n)!=n) {
  27. if (lastfile)
  28. lastfile->rescuing = 1;
  29. errstr(buf, sizeof buf);
  30. if (downloaded)
  31. fprint(2, "read error: %s\n", buf);
  32. rescue();
  33. exits("read");
  34. }
  35. return n;
  36. }
  37. int
  38. Write(int f, void *a, int n)
  39. {
  40. int m;
  41. if((m=write(f, (char *)a, n))!=n)
  42. syserror("write");
  43. return m;
  44. }
  45. void
  46. Seek(int f, long n, int w)
  47. {
  48. if(seek(f, n, w)==-1)
  49. syserror("seek");
  50. }