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