From 90549903b725742e36cd1dd93b479d012829cd49 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Thu, 1 Oct 2015 02:22:45 +0200 Subject: [PATCH] (retro_stat.c) Implement path_get_size --- libretro-common/file/file_extract.c | 11 +++-------- libretro-common/file/retro_stat.c | 20 ++++++++++++++++---- libretro-common/include/retro_stat.h | 2 ++ 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/libretro-common/file/file_extract.c b/libretro-common/file/file_extract.c index 9557dc4c5c..b2b789b724 100644 --- a/libretro-common/file/file_extract.c +++ b/libretro-common/file/file_extract.c @@ -30,6 +30,7 @@ #include #include #include +#include #include #include @@ -101,7 +102,6 @@ static size_t zlib_file_size(void *handle) static void *zlib_file_open(const char *path) { - struct stat fds; zlib_file_data_t *data = (zlib_file_data_t*)calloc(1, sizeof(*data)); if (!data) @@ -109,16 +109,11 @@ static void *zlib_file_open(const char *path) data->fd = open(path, O_RDONLY); + /* Failed to open archive. */ if (data->fd < 0) - { - /* Failed to open archive. */ - goto error; - } - - if (fstat(data->fd, &fds) < 0) goto error; - data->size = fds.st_size; + data->size = path_get_size(path); if (!data->size) return data; diff --git a/libretro-common/file/retro_stat.c b/libretro-common/file/retro_stat.c index 8ab43835b4..17e1dd0eca 100644 --- a/libretro-common/file/retro_stat.c +++ b/libretro-common/file/retro_stat.c @@ -79,7 +79,7 @@ enum stat_mode IS_VALID }; -static bool path_stat(const char *path, enum stat_mode mode) +static bool path_stat(const char *path, enum stat_mode mode, ssize_t *size) { #if defined(VITA) || defined(PSP) SceIoStat buf; @@ -109,6 +109,9 @@ static bool path_stat(const char *path, enum stat_mode mode) return false; #endif + if (size) + *size = buf.st_size; + switch (mode) { case IS_DIRECTORY: @@ -144,17 +147,26 @@ static bool path_stat(const char *path, enum stat_mode mode) */ bool path_is_directory(const char *path) { - return path_stat(path, IS_DIRECTORY); + return path_stat(path, IS_DIRECTORY, NULL); } bool path_is_character_special(const char *path) { - return path_stat(path, IS_CHARACTER_SPECIAL); + return path_stat(path, IS_CHARACTER_SPECIAL, NULL); } bool path_is_valid(const char *path) { - return path_stat(path, IS_VALID); + return path_stat(path, IS_VALID, NULL); +} + +ssize_t path_get_size(const char *path) +{ + ssize_t filesize; + if (path_stat(path, IS_VALID, &filesize)) + return filesize; + + return -1; } /** diff --git a/libretro-common/include/retro_stat.h b/libretro-common/include/retro_stat.h index 77f13d0acb..032b2d9235 100644 --- a/libretro-common/include/retro_stat.h +++ b/libretro-common/include/retro_stat.h @@ -46,6 +46,8 @@ bool path_is_character_special(const char *path); bool path_is_valid(const char *path); +ssize_t path_get_size(const char *path); + /** * path_mkdir_norecurse: * @dir : directory