From a8322df38cbc72dddb3177cab3cef9f5bb521f08 Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Sun, 15 Sep 2019 20:47:09 +0200 Subject: Fix: work out the *current* file size when opening a file Signed-off-by: David Oberhollenzer --- lib/sqfs/io_file.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'lib/sqfs') diff --git a/lib/sqfs/io_file.c b/lib/sqfs/io_file.c index b57eddd..bb5ef48 100644 --- a/lib/sqfs/io_file.c +++ b/lib/sqfs/io_file.c @@ -10,6 +10,7 @@ #include "sqfs/io.h" #include "sqfs/error.h" +#include #include #include #include @@ -111,6 +112,7 @@ sqfs_file_t *sqfs_open_file(const char *filename, int flags) sqfs_file_stdio_t *file; int open_mode, temp; sqfs_file_t *base; + struct stat sb; if (flags & ~SQFS_FILE_OPEN_ALL_FLAGS) { errno = EINVAL; @@ -142,6 +144,16 @@ sqfs_file_t *sqfs_open_file(const char *filename, int flags) return NULL; } + if (fstat(file->fd, &sb)) { + temp = errno; + close(file->fd); + free(file); + errno = temp; + return NULL; + } + + file->size = sb.st_size; + base->destroy = stdio_destroy; base->read_at = stdio_read_at; base->write_at = stdio_write_at; -- cgit v1.2.3