summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2020-02-16 23:51:21 +0100
committerwm4 <wm4@nowhere>2020-02-16 23:51:21 +0100
commitaafc434f00b339fa7f15e6114311da0fcc5e3269 (patch)
treee27ecc1ea2b9544b1665b2357e4243b2d570686e
parent1a54339705f71a67faa900a125d467ba121e3ae6 (diff)
downloadmpv-aafc434f00b339fa7f15e6114311da0fcc5e3269.tar.bz2
mpv-aafc434f00b339fa7f15e6114311da0fcc5e3269.tar.xz
stream_file: remove file size caching
With the last 3 commits, this caching should be completely unnecessary.
-rw-r--r--stream/stream_file.c21
1 files changed, 7 insertions, 14 deletions
diff --git a/stream/stream_file.c b/stream/stream_file.c
index 9f83b73dd1..ec801cd82f 100644
--- a/stream/stream_file.c
+++ b/stream/stream_file.c
@@ -64,7 +64,6 @@ struct priv {
bool use_poll;
bool regular_file;
bool appending;
- int64_t cached_size; // -2: invalid, -1: unknown
int64_t orig_size;
struct mp_cancel *cancel;
};
@@ -76,25 +75,20 @@ struct priv {
static int64_t get_size(stream_t *s)
{
struct priv *p = s->priv;
- if (p->cached_size == -2) {
- int64_t size = -1;
- struct stat st;
- 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;
+ struct stat st;
+ if (fstat(p->fd, &st) == 0) {
+ if (st.st_size <= 0 && !s->seekable)
+ st.st_size = -1;
+ if (st.st_size >= 0)
+ return st.st_size;
}
- return p->cached_size;
+ return -1;
}
static int fill_buffer(stream_t *s, void *buffer, int max_len)
{
struct priv *p = s->priv;
- p->cached_size = -2; // always invalidate cached size
-
#ifndef __MINGW32__
if (p->use_poll) {
int c = mp_cancel_get_fd(p->cancel);
@@ -257,7 +251,6 @@ static int open_f(stream_t *stream)
struct priv *p = talloc_ptrtype(stream, p);
*p = (struct priv) {
.fd = -1,
- .cached_size = -2,
};
stream->priv = p;
stream->is_local_file = true;