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>.
Unified · Split
| @@ -333,13 +333,11 @@ static void set_endiannesses(sox_format_t * ft) · 332 unmodified lines | ||
| 333 | 333 | |
| 334 | 334 | static sox_bool is_seekable(sox_format_t const * ft) |
| 335 | 335 | { |
| 336 | − struct stat st; | |
| 337 | − | |
| 338 | 336 | assert(ft); |
| 339 | 337 | if (!ft->fp) |
| 340 | 338 | return sox_false; |
| 341 | − fstat(fileno((FILE*)ft->fp), &st); | |
| 342 | − return ((st.st_mode & S_IFMT) == S_IFREG); | |
| 339 | + | |
| 340 | + return !fseek(ft->fp, 0, SEEK_CUR); | |
| 343 | 341 | } |
| 344 | 342 | |
| 345 | 343 | /* check that all settings have been given */ |