mirror of
https://github.com/libretro/RetroArch
synced 2025-02-20 06:40:18 +00:00
(retro_stat.c) Implement path_get_size
This commit is contained in:
parent
38d59e1e86
commit
90549903b7
@ -30,6 +30,7 @@
|
|||||||
#include <file/file_extract.h>
|
#include <file/file_extract.h>
|
||||||
#include <file/file_path.h>
|
#include <file/file_path.h>
|
||||||
#include <retro_file.h>
|
#include <retro_file.h>
|
||||||
|
#include <retro_stat.h>
|
||||||
#include <retro_miscellaneous.h>
|
#include <retro_miscellaneous.h>
|
||||||
#include <string/string_list.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)
|
static void *zlib_file_open(const char *path)
|
||||||
{
|
{
|
||||||
struct stat fds;
|
|
||||||
zlib_file_data_t *data = (zlib_file_data_t*)calloc(1, sizeof(*data));
|
zlib_file_data_t *data = (zlib_file_data_t*)calloc(1, sizeof(*data));
|
||||||
|
|
||||||
if (!data)
|
if (!data)
|
||||||
@ -109,16 +109,11 @@ static void *zlib_file_open(const char *path)
|
|||||||
|
|
||||||
data->fd = open(path, O_RDONLY);
|
data->fd = open(path, O_RDONLY);
|
||||||
|
|
||||||
|
/* Failed to open archive. */
|
||||||
if (data->fd < 0)
|
if (data->fd < 0)
|
||||||
{
|
|
||||||
/* Failed to open archive. */
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fstat(data->fd, &fds) < 0)
|
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
data->size = fds.st_size;
|
data->size = path_get_size(path);
|
||||||
if (!data->size)
|
if (!data->size)
|
||||||
return data;
|
return data;
|
||||||
|
|
||||||
|
@ -79,7 +79,7 @@ enum stat_mode
|
|||||||
IS_VALID
|
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)
|
#if defined(VITA) || defined(PSP)
|
||||||
SceIoStat buf;
|
SceIoStat buf;
|
||||||
@ -109,6 +109,9 @@ static bool path_stat(const char *path, enum stat_mode mode)
|
|||||||
return false;
|
return false;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
if (size)
|
||||||
|
*size = buf.st_size;
|
||||||
|
|
||||||
switch (mode)
|
switch (mode)
|
||||||
{
|
{
|
||||||
case IS_DIRECTORY:
|
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)
|
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)
|
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)
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -46,6 +46,8 @@ bool path_is_character_special(const char *path);
|
|||||||
|
|
||||||
bool path_is_valid(const char *path);
|
bool path_is_valid(const char *path);
|
||||||
|
|
||||||
|
ssize_t path_get_size(const char *path);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* path_mkdir_norecurse:
|
* path_mkdir_norecurse:
|
||||||
* @dir : directory
|
* @dir : directory
|
||||||
|
Loading…
x
Reference in New Issue
Block a user