mirror of https://github.com/mpv-player/mpv
stream_file: use fstat() instead of lseek() to determine file size
It appears using lseek() to seek to the end and back to determine file size is inefficient in some cases (like with CIFS, see #7408). Even Windows supports fstat() (well, almost, but we already have a wrapper), so use that. It's unknown whether that will work better. Although I like it more, because it doesn't mess with the file position.
This commit is contained in:
parent
a19d918816
commit
74a2c0fb7f
|
@ -77,9 +77,14 @@ static int64_t get_size(stream_t *s)
|
||||||
{
|
{
|
||||||
struct priv *p = s->priv;
|
struct priv *p = s->priv;
|
||||||
if (p->cached_size == -2) {
|
if (p->cached_size == -2) {
|
||||||
off_t size = lseek(p->fd, 0, SEEK_END);
|
int64_t size = -1;
|
||||||
lseek(p->fd, s->pos, SEEK_SET);
|
struct stat st;
|
||||||
p->cached_size = size < 0 ? -1 : size;
|
if (fstat(p->fd, &st) == 0) {
|
||||||
|
if (st.st_size <= 0 && !s->seekable)
|
||||||
|
st.st_size = -1;
|
||||||
|
size = st.st_size < 0 ? -1 : st.st_size;
|
||||||
|
}
|
||||||
|
p->cached_size = size;
|
||||||
}
|
}
|
||||||
return p->cached_size;
|
return p->cached_size;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue