1#include <stdio.h>23#undef fwrite45size_t6fwrite(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;1112 if (size == 0)13 return 0;1415 for (n = 0; n < nmemb; n++) {16 i = size;17 do18 putc(*bp++, fp);19 while (--i);20 if (ferror(fp))21 break;22 }2324 return n;25}