9os

Experimental kernel using plan9 ideas for embedded device
git clone git://git.simple-cc.org/9os
Log | Files | Refs | README | LICENSE

fread.c (342B)


      1 #include <stdio.h>
      2 #undef fread
      3 
      4 size_t
      5 fread(void * restrict ptr, size_t size, size_t nmemb,
      6       FILE * restrict fp)
      7 {
      8 	unsigned char *bp = ptr;
      9 	size_t n, i;
     10 	int c;
     11 
     12 	if (size == 0)
     13 		return 0;
     14 
     15 	for (n = 0; n < nmemb; n++) {
     16 		i = size;
     17 		do {
     18 			if ((c = getc(fp)) == EOF)
     19 				return n;
     20 			*bp++ = c;
     21 		} while (--i);
     22 	}
     23 
     24 	return n;
     25 }