summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-09-15 20:47:09 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-09-15 20:47:09 +0200
commita8322df38cbc72dddb3177cab3cef9f5bb521f08 (patch)
tree694a6a5b54e183ab282b5dcda5084a4b293d87d1 /lib
parent428aa363dd2b44756a5b16aa17e8c2030de801a0 (diff)
Fix: work out the *current* file size when opening a file
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib')
-rw-r--r--lib/sqfs/io_file.c12
1 files changed, 12 insertions, 0 deletions
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 <sys/stat.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
@@ -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;