fread.c (343B)
1 #include <stdio.h> 2 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 int c; 12 13 if (size == 0) 14 return 0; 15 16 for (n = 0; n < nmemb; n++) { 17 i = size; 18 do { 19 if ((c = getc(fp)) == EOF) 20 return n; 21 *bp++ = c; 22 } while (--i); 23 } 24 25 return n; 26 }