9os

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

fwrite.c (335B)


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