"If an error occurs, or the end-of-file is reached, the return value is a
short object count (or zero)."
According to this, checking ferror is unnecessary for fwrites. However you
are right that just checking that the len is 0 is not enough, instead we
should check that the number of bytes written is equal to the number of
bytes we wanted to write, i.e.
if ( fwrite(data, 1, len, f) < len )
return false;
There are a few more fwrite calls in the file before that, I will give it
a quick pass and submit a patch later today.