From: Paul Brossier Date: Tue, 8 Jan 2019 17:51:16 +0000 (+0100) Subject: [sink_wavwrite] call fflush in open X-Git-Tag: 0.4.9~5 X-Git-Url: https://git.aubio.org/?p=aubio.git;a=commitdiff_plain;h=65a4fb4d95e51cf33ee9f90a5dfb20f5addd9f7c [sink_wavwrite] call fflush in open This ensures the file header was actually written correctly, and fails otherwise, for instance when the target disk-system is full. --- diff --git a/src/io/sink_wavwrite.c b/src/io/sink_wavwrite.c index d2c27366..8ea05b76 100644 --- a/src/io/sink_wavwrite.c +++ b/src/io/sink_wavwrite.c @@ -211,9 +211,11 @@ uint_t aubio_sink_wavwrite_open(aubio_sink_wavwrite_t *s) { written += fwrite(write_little_endian(0, buf, 4), 4, 1, s->fid); // fwrite(*, *, 1, s->fid) was called 13 times, check success - if (written != 13) { - AUBIO_STRERR("sink_wavwrite: writing header to %s failed, expected %d" - " write but got only %d (%s)\n", s->path, 13, written, errorstr); + if (written != 13 || fflush(s->fid)) { + AUBIO_STRERR("sink_wavwrite: writing header to %s failed" + " (wrote %d/%d, %s)\n", s->path, written, 13, errorstr); + fclose(s->fid); + s->fid = NULL; return AUBIO_FAIL; }