History

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>.

Mans Rullgard committed 6 years ago

Commit bb389341 parent c972f901 file · +2 −4Browse files

Unified · Split

src/formats.c+2−4
@@ -333,13 +333,11 @@ static void set_endiannesses(sox_format_t * ft) · 332 unmodified lines
333333
334334 static sox_bool is_seekable(sox_format_t const * ft)
335335 {
336− struct stat st;
337−
338336 assert(ft);
339337 if (!ft->fp)
340338 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);
343341 }
344342
345343 /* check that all settings have been given */

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t