ref: bb38934e11035c8fab141f70dabda3afdd17da36
parent: c972f90f8d7f2e4ff8d2c865ef7b2f897a408de7
author: Mans Rullgard <mans@mansr.com>
date: Tue Aug 4 13:19:49 EDT 2020
format: improve is_seekable() test Streams opened with fmemopen() do not have an underlying file descriptor, so the fstat() will fail, and a random result is returned. A simpler method that works regardless of file type is to call fseek() and check if it reports success. Suggested by Stefan Sauer <ensonic@google.com>.
--- a/src/formats.c
+++ b/src/formats.c
@@ -333,13 +333,11 @@
static sox_bool is_seekable(sox_format_t const * ft)
{
- struct stat st;
-
assert(ft);
if (!ft->fp)
return sox_false;
- fstat(fileno((FILE*)ft->fp), &st);
- return ((st.st_mode & S_IFMT) == S_IFREG);
+
+ return !fseek(ft->fp, 0, SEEK_CUR);
}
/* check that all settings have been given */