scc

simple C compiler
git clone git://git.2f30.org/scc
Log | Files | Refs | README | LICENSE

fread.c (338B)


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