From 65a4fb4d95e51cf33ee9f90a5dfb20f5addd9f7c Mon Sep 17 00:00:00 2001 From: Paul Brossier Date: Tue, 8 Jan 2019 18:51:16 +0100 Subject: [PATCH] [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. --- src/io/sink_wavwrite.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) 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; } -- 2.11.0