Blob


1 #include "sam.h"
3 static int inerror=FALSE;
5 /*
6 * A reasonable interface to the system calls
7 */
9 void
10 resetsys(void)
11 {
12 inerror = FALSE;
13 }
15 void
16 syserror(char *a)
17 {
18 char buf[ERRMAX];
20 if(!inerror){
21 inerror=TRUE;
22 errstr(buf, sizeof buf);
23 dprint("%s: ", a);
24 error_s(Eio, buf);
25 }
26 }
28 int
29 Read(int f, void *a, int n)
30 {
31 char buf[ERRMAX];
33 if(read(f, (char *)a, n)!=n) {
34 if (lastfile)
35 lastfile->rescuing = 1;
36 errstr(buf, sizeof buf);
37 if (downloaded)
38 fprint(2, "read error: %s\n", buf);
39 rescue();
40 exits("read");
41 }
42 return n;
43 }
45 int
46 Write(int f, void *a, int n)
47 {
48 int m;
50 if((m=write(f, (char *)a, n))!=n)
51 syserror("write");
52 return m;
53 }
55 void
56 Seek(int f, long n, int w)
57 {
58 if(seek(f, n, w)==-1)
59 syserror("seek");
60 }
62 void
63 Close(int f)
64 {
65 if(close(f) < 0)
66 syserror("close");
67 }