scc

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

fwrite.c (350B)


      1 
      2 #include <stdio.h>
      3 #undef fwrite
      4 
      5 size_t
      6 fwrite(const void * restrict ptr, size_t size, size_t nmemb,
      7        FILE * restrict fp)
      8 {
      9 	const 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 (putc(*bp++, fp) == EOF)
     18 				return n;
     19 		}
     20 	}
     21 
     22 	return n;
     23 }