From fa148febc581ec277e9dee019c9b5d0c1d5a639e Mon Sep 17 00:00:00 2001 From: Avril Date: Tue, 18 May 2021 06:25:09 +0100 Subject: [PATCH] better atomic fwrite_all internal --- src/bits.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/bits.c b/src/bits.c index e6d2462..b00293c 100644 --- a/src/bits.c +++ b/src/bits.c @@ -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; }