9base

revived minimalist port of Plan 9 userland to Unix
git clone git://git.suckless.org/9base
Log | Files | Refs | README | LICENSE

sys.c (745B)


      1 #include "sam.h"
      2 
      3 static int inerror=FALSE;
      4 
      5 /*
      6  * A reasonable interface to the system calls
      7  */
      8 
      9 void
     10 resetsys(void)
     11 {
     12 	inerror = FALSE;
     13 }
     14 
     15 void
     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
     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
     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
     56 Seek(int f, long n, int w)
     57 {
     58 	if(seek(f, n, w)==-1)
     59 		syserror("seek");
     60 }