better atomic fwrite_all internal

master
Avril 4 years ago
parent bbbeec9ed7
commit fa148febc5
Signed by: flanchan
GPG Key ID: 284488987C31F630

@ -15,13 +15,12 @@ static inline int sfread(void* out, size_t *restrict size, FILE* f)
return !!(*size = (size_t)fread(out, 1, *size, f));
}
static int fwrite_all(const void* buf, size_t esz, size_t num, FILE* out)
static int fwrite_all(const void* _buf, size_t sz, size_t num, FILE* out)
{
register size_t w, done=0;
register size_t fsz = esz * num;
const char* tbuf = (const char*)buf;
while( (w = fwrite(tbuf+done, 1, fsz-done, out)) > 0 && done < fsz) done+=w;
if (done!=fsz) return 0;
register const unsigned char* buf = _buf;
while( (w = fwrite(buf+done, sz, num-done, out)) > 0 && done < num) done+=w;
if (done!=num) return 0;
else return 1;
}

Loading…
Cancel
Save