git: 9front

Download patch

ref: a867b0cd1535a0b2eb42e1877121fb736a734da1
parent: 5dbbd484ebeaeb8be5b88c554099a41c5a01228e
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Thu Nov 16 09:15:00 EST 2017

audio/flacdec: add eof handler avoiding endless spinning on broken files (thanks deuteron)

--- a/sys/src/cmd/audio/flacdec/flacdec.c
+++ b/sys/src/cmd/audio/flacdec/flacdec.c
@@ -119,6 +119,12 @@
 	fprintf(stderr, "decode error: %s (%d)\n", FLAC__StreamDecoderErrorStatusString[status], status);
 }
 
+static FLAC__bool
+checkeof(const FLAC__StreamDecoder*, void*)
+{
+	return feof(stdin);
+}
+
 int main(int argc, char *argv[])
 {
 	FLAC__bool ok = true;
@@ -125,7 +131,7 @@
 	FLAC__StreamDecoder *dec = 0;
 
 	dec = FLAC__stream_decoder_new();
-	FLAC__stream_decoder_init_stream(dec, decinput, NULL, NULL, NULL, NULL, decoutput, NULL, decerror, NULL);
+	FLAC__stream_decoder_init_stream(dec, decinput, NULL, NULL, NULL, checkeof, decoutput, NULL, decerror, NULL);
 	FLAC__stream_decoder_process_until_end_of_stream(dec);
 	FLAC__stream_decoder_finish(dec);
 	return 0;
--