shithub: scc

ref: 95b6c63659cb4fa379a56778c32093728dc74c1a
dir: /lib/c/src/fwrite.c/

View raw version

#include <stdio.h>
#undef fwrite

size_t
fwrite(const void * restrict ptr, size_t size, size_t nmemb,
       FILE * restrict fp)
{
	const unsigned char *bp = ptr;
	size_t n, i;

	if (nmemb == 0 || size == 0)
		return 0;

	for (n = 0; n < nmemb; n++) {
		for (i = 0; i < size; ++i) {
			if (putc(*bp++, fp) == EOF)
				return n;
		}
	}

	return n;
}