xref: /plan9/sys/src/cmd/sam/sys.c (revision 9a747e4fd48b9f4522c70c07e8f882a15030f964)
1 #include "sam.h"
2 
3 static int inerror=FALSE;
4 
5 /*
6  * A reasonable interface to the system calls
7  */
8 
9 void
resetsys(void)10 resetsys(void)
11 {
12 	inerror = FALSE;
13 }
14 
15 void
syserror(char * a)16 syserror(char *a)
17 {
18 	char buf[ERRMAX];
19 
20 	if(!inerror){
21 		inerror=TRUE;
22 		errstr(buf, sizeof buf);
23 		dprint("%s: ", a);
24 		error_s(Eio, buf);
25 	}
26 }
27 
28 int
Read(int f,void * a,int n)29 Read(int f, void *a, int n)
30 {
31 	char buf[ERRMAX];
32 
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 }
44 
45 int
Write(int f,void * a,int n)46 Write(int f, void *a, int n)
47 {
48 	int m;
49 
50 	if((m=write(f, (char *)a, n))!=n)
51 		syserror("write");
52 	return m;
53 }
54 
55 void
Seek(int f,long n,int w)56 Seek(int f, long n, int w)
57 {
58 	if(seek(f, n, w)==-1)
59 		syserror("seek");
60 }
61