9base

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

readn.c (219B)


      1 #include <lib9.h>
      2 
      3 long
      4 readn(int f, void *av, long n)
      5 {
      6 	char *a;
      7 	long m, t;
      8 
      9 	a = av;
     10 	t = 0;
     11 	while(t < n){
     12 		m = read(f, a+t, n-t);
     13 		if(m <= 0){
     14 			if(t == 0)
     15 				return m;
     16 			break;
     17 		}
     18 		t += m;
     19 	}
     20 	return t;
     21 }