add flushed fwrite in Valgrind mode
[platform/upstream/flac.git] / src / test_libFLAC / file_utils.c
index aff1ab7..e678564 100644 (file)
 #endif
 #define min(a,b) ((a)<(b)?(a):(b))
 
+#ifdef FLAC__VALGRIND_TESTING
+static size_t local__fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream)
+{
+       size_t ret = fwrite(ptr, size, nmemb, stream);
+       if(!ferror(stream))
+               fflush(stream);
+       return ret;
+}
+#else
+#define local__fwrite fwrite
+#endif
+
 typedef struct {
        FILE *file;
 } encoder_client_struct;
@@ -38,7 +50,7 @@ static FLAC__StreamEncoderWriteStatus encoder_write_callback_(const FLAC__Stream
 
        (void)encoder, (void)samples, (void)current_frame;
 
-       if(fwrite(buffer, 1, bytes, ecd->file) != bytes)
+       if(local__fwrite(buffer, 1, bytes, ecd->file) != bytes)
                return FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR;
        else
                return FLAC__STREAM_ENCODER_WRITE_STATUS_OK;