(retro_stat.c) Implement path_get_size

This commit is contained in:
twinaphex 2015-10-01 02:22:45 +02:00
parent 38d59e1e86
commit 90549903b7
3 changed files with 21 additions and 12 deletions

View File

@ -30,6 +30,7 @@
#include <file/file_extract.h>
#include <file/file_path.h>
#include <retro_file.h>
#include <retro_stat.h>
#include <retro_miscellaneous.h>
#include <string/string_list.h>
@ -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;

View File

@ -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;
}
/**

View File

@ -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