sys.c 1.1 KB

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