From 43cb942cd46729003405f7a6f3e5eaf6a7b95d84 Mon Sep 17 00:00:00 2001 From: Martin Storsjo Date: Fri, 7 Feb 2014 14:59:20 +0200 Subject: [PATCH] Use skip instead of fseek fseek(SEEK_CUR) doesn't work for nonseekable streams (such as pipes). Only do this for skipping past small chunks; don't use it for skipping past the actual data for non-streamed input. --- wavreader.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/wavreader.c b/wavreader.c index 194046b..76443e0 100644 --- a/wavreader.c +++ b/wavreader.c @@ -63,6 +63,12 @@ static uint16_t read_int16(struct wav_reader* wr) { return value; } +static void skip(FILE *f, int n) { + int i; + for (i = 0; i < n; i++) + fgetc(f); +} + void* wav_read_open(const char *filename) { struct wav_reader* wr = (struct wav_reader*) malloc(sizeof(*wr)); long data_pos = 0; @@ -118,7 +124,7 @@ void* wav_read_open(const char *filename) { wr->byte_rate = read_int32(wr); wr->block_align = read_int16(wr); wr->bits_per_sample = read_int16(wr); - fseek(wr->wav, sublength - 16, SEEK_CUR); + skip(wr->wav, sublength - 16); } else if (subtag == TAG('d', 'a', 't', 'a')) { data_pos = ftell(wr->wav); wr->data_length = sublength; @@ -128,7 +134,7 @@ void* wav_read_open(const char *filename) { } fseek(wr->wav, sublength, SEEK_CUR); } else { - fseek(wr->wav, sublength, SEEK_CUR); + skip(wr->wav, sublength); } length -= sublength; }