Commit 0da96d3c authored by nu774's avatar nu774 Committed by Erik de Castro Lopo
Browse files

Fix to allow the flac command to parse piped WAV input with


WAVEFORMATEXTENSIBLE format.

MinGW's fseeko() doesn't return error for the attempt to seek on non
seekable file (same behavior as MSVC).
The simplest solution would be to change #ifdef _MSC_VER to #ifdef
_WIN32 here.
Instead, this patch tests file with fstat(), and use fseeko() only when
it is a regular file.
This is confirmed to work properly both on MSVC and MinGW, can seek if
stdin is a redirected regular file, and doesn't require #ifdef.
Signed-off-by: Erik de Castro Lopo's avatarErik de Castro Lopo <erikd@mega-nerd.com>
parent 55788ea9
......@@ -26,6 +26,7 @@
#include <stdio.h> /* for FILE etc. */
#include <stdlib.h> /* for malloc */
#include <string.h> /* for strcmp(), strerror() */
#include <sys/stat.h>
#include "FLAC/all.h"
#include "share/alloc.h"
#include "share/grabbag.h"
......@@ -2799,29 +2800,18 @@ FLAC__bool read_sane_extended(FILE *f, FLAC__uint32 *val, const char *fn)
FLAC__bool fskip_ahead(FILE *f, FLAC__uint64 offset)
{
static unsigned char dump[8192];
struct stat stb;
#ifdef _MSC_VER
if(f == stdin) {
/* MS' stdio impl can't even seek forward on stdin, have to use pure non-fseek() version: */
while(offset > 0) {
const long need = (long)min(offset, sizeof(dump));
if((long)fread(dump, 1, need, f) < need)
return false;
offset -= need;
}
}
else
#endif
if(fstat(fileno(f), &stb) == 0 && (stb.st_mode & S_IFMT) == S_IFREG)
{
while(offset > 0) {
long need = (long)min(offset, LONG_MAX);
if(fseeko(f, need, SEEK_CUR) < 0) {
need = (long)min(offset, sizeof(dump));
if((long)fread(dump, 1, need, f) < need)
return false;
}
offset -= need;
}
if(fseeko(f, offset, SEEK_CUR) == 0)
return true;
}
while(offset > 0) {
const long need = (long)min(offset, sizeof(dump));
if((long)fread(dump, 1, need, f) < need)
return false;
offset -= need;
}
return true;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment