Create retro_stat.c/retro_stat.h

This commit is contained in:
twinaphex 2015-09-22 01:45:16 +02:00
parent 05704f6b9c
commit 3db688d477
21 changed files with 293 additions and 200 deletions

View File

@ -136,6 +136,7 @@ OBJ += frontend/frontend.o \
libretro-common/file/dir_list.o \
libretro-common/file/retro_dirent.o \
libretro-common/file/retro_file.o \
libretro-common/file/retro_stat.o \
libretro-common/string/string_list.o \
libretro-common/string/stdstring.o \
libretro-common/memmap/memalign.o \

View File

@ -26,6 +26,7 @@ PPU_SRCS = frontend/frontend_salamander.c \
libretro-common/file/file_path.c \
libretro-common/file/dir_list.c \
libretro-common/file/retro_dirent.c \
libretro-common/file/retro_stat.c \
libretro-common/hash/rhash.c \
libretro-common/string/string_list.c \
libretro-common/compat/compat.c \

View File

@ -42,6 +42,7 @@ OBJS = frontend/frontend_salamander.o \
libretro-common/compat/compat.o \
libretro-common/file/config_file.o \
libretro-common/file/retro_file.o \
libretro-common/file/retro_stat.o \
libretro-common/hash/rhash.o \
bootstrap/psp1/kernel_functions.o

View File

@ -50,6 +50,7 @@ OBJ = frontend/frontend_salamander.o \
libretro-common/file/dir_list.o \
libretro-common/file/retro_file.o \
libretro-common/file/retro_dirent.o \
libretro-common/file/retro_stat.o \
libretro-common/compat/compat.o \
libretro-common/file/config_file.o \
$(APP_BOOTER_DIR)/app_booter.binobj

View File

@ -20,6 +20,7 @@
#include <file/file_path.h>
#include <compat/strl.h>
#include <compat/posix_string.h>
#include <retro_stat.h>
#include "config.def.h"
#include "input/input_common.h"

View File

@ -34,6 +34,7 @@
#include <file/file_path.h>
#include <file/file_extract.h>
#include <retro_file.h>
#include <retro_stat.h>
#include "msg_hash.h"
#include "content.h"

View File

@ -16,6 +16,7 @@
*/
#include <file/file_path.h>
#include <retro_stat.h>
#include "frontend.h"
#include "../system.h"

View File

@ -578,6 +578,7 @@ FILE
#endif
#include "../libretro-common/file/retro_dirent.c"
#include "../libretro-common/file/retro_file.c"
#include "../libretro-common/file/retro_stat.c"
#include "../dir_list_special.c"
#include "../libretro-common/string/string_list.c"
#include "../libretro-common/string/stdstring.c"

View File

@ -43,6 +43,7 @@
#include <compat/msvc.h>
#include <file/config_file.h>
#include <file/file_path.h>
#include <retro_stat.h>
#include <string/string_list.h>
#include <rhash.h>

View File

@ -27,41 +27,11 @@
#include <time.h>
#include <errno.h>
#if defined(_WIN32)
#ifdef _MSC_VER
#define setmode _setmode
#endif
#ifdef _XBOX
#include <xtl.h>
#define INVALID_FILE_ATTRIBUTES -1
#else
#include <io.h>
#include <fcntl.h>
#include <direct.h>
#include <windows.h>
#endif
#elif defined(VITA)
#define SCE_ERROR_ERRNO_EEXIST 0x80010011
#include <psp2/io/fcntl.h>
#include <psp2/io/dirent.h>
#include <psp2/io/stat.h>
#else
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#endif
#if defined(PSP)
#include <pspkernel.h>
#endif
#ifdef __HAIKU__
#include <kernel/image.h>
#endif
#if (defined(__CELLOS_LV2__) && !defined(__PSL1GHT__)) || defined(__QNX__) || defined(PSP)
#include <unistd.h> /* stat() is defined here */
#endif
#include <retro_stat.h>
#include <file/file_path.h>
@ -70,18 +40,6 @@
#include <retro_assert.h>
#include <retro_miscellaneous.h>
#if defined(__CELLOS_LV2__)
#ifndef S_ISDIR
#define S_ISDIR(x) (x & 0040000)
#endif
#endif
#if defined(VITA)
#define FIO_SO_ISDIR PSP2_S_ISDIR
#endif
/**
* path_get_extension:
* @path : path
@ -165,61 +123,6 @@ bool path_is_compressed_file(const char* path)
return false;
}
/**
* path_is_directory:
* @path : path
*
* Checks if path is a directory.
*
* Returns: true (1) if path is a directory, otherwise false (0).
*/
bool path_is_directory(const char *path)
{
#if defined(VITA) || defined(PSP)
SceIoStat buf;
if (sceIoGetstat(path, &buf) < 0)
return false;
return FIO_SO_ISDIR(buf.st_mode);
#elif defined(__CELLOS_LV2__)
CellFsStat buf;
if (cellFsStat(path, &buf) < 0)
return false;
return ((buf.st_mode & S_IFMT) == S_IFDIR);
#elif defined(_WIN32)
DWORD ret = GetFileAttributes(path);
return (ret & FILE_ATTRIBUTE_DIRECTORY) && (ret != INVALID_FILE_ATTRIBUTES);
#else
struct stat buf;
if (stat(path, &buf) < 0)
return false;
return S_ISDIR(buf.st_mode);
#endif
}
bool path_is_valid(const char *path)
{
#if defined(VITA) || defined(PSP)
SceIoStat buf;
if (sceIoGetstat(path, &buf) < 0)
return false;
return true;
#elif defined(__CELLOS_LV2__)
CellFsStat buf;
if (cellFsStat(path, &buf) < 0)
return false;
return true;
#elif defined(_WIN32)
DWORD ret = GetFileAttributes(path);
return (ret != INVALID_FILE_ATTRIBUTES);
#else
struct stat buf;
if (stat(path, &buf) < 0)
return false;
return true;
#endif
}
/**
* path_file_exists:
* @path : path
@ -578,84 +481,6 @@ void path_resolve_realpath(char *buf, size_t size)
#endif
}
/**
* path_mkdir_norecurse:
* @dir : directory
*
* Create directory on filesystem.
*
* Returns: true (1) if directory could be created, otherwise false (0).
**/
static bool path_mkdir_norecurse(const char *dir)
{
int ret;
#if defined(_WIN32)
ret = _mkdir(dir);
#elif defined(IOS)
ret = mkdir(dir, 0755);
#elif defined(VITA) || defined(PSP)
ret = sceIoMkdir(dir, 0777);
#else
ret = mkdir(dir, 0750);
#endif
/* Don't treat this as an error. */
#if defined(VITA)
if ((ret == SCE_ERROR_ERRNO_EEXIST) && path_is_directory(dir))
ret = 0;
#else
if (ret < 0 && errno == EEXIST && path_is_directory(dir))
ret = 0;
#endif
if (ret < 0)
printf("mkdir(%s) error: %s.\n", dir, strerror(errno));
return ret == 0;
}
/**
* path_mkdir:
* @dir : directory
*
* Create directory on filesystem.
*
* Returns: true (1) if directory could be created, otherwise false (0).
**/
bool path_mkdir(const char *dir)
{
const char *target = NULL;
/* Use heap. Real chance of stack overflow if we recurse too hard. */
char *basedir = strdup(dir);
bool ret = false;
if (!basedir)
return false;
path_parent_dir(basedir);
if (!*basedir || !strcmp(basedir, dir))
goto end;
if (path_is_directory(basedir))
{
target = dir;
ret = path_mkdir_norecurse(dir);
}
else
{
target = basedir;
ret = path_mkdir(basedir);
if (ret)
{
target = dir;
ret = path_mkdir_norecurse(dir);
}
}
end:
if (target && !ret)
printf("Failed to create directory: \"%s\".\n", target);
free(basedir);
return ret;
}
/**
* fill_pathname_resolve_relative:
* @out_path : output path

View File

@ -36,6 +36,7 @@
#include <boolean.h>
#include <file/file_path.h>
#include <retro_stat.h>
struct RDIR
{

View File

@ -1,4 +1,3 @@
#include <retro_file.h>
#include <stdio.h>
#include <stdlib.h>
@ -48,6 +47,8 @@
#include <retro_log.h>
#endif
#include <retro_file.h>
#if 1
#define HAVE_BUFFERED_IO 1
#endif

View File

@ -0,0 +1,213 @@
/* Copyright (C) 2010-2015 The RetroArch team
*
* ---------------------------------------------------------------------------------------
* The following license statement only applies to this file (retro_stat.c).
* ---------------------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge,
* to any person obtaining a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <stdlib.h>
#include <errno.h>
#if defined(_WIN32)
#ifdef _MSC_VER
#define setmode _setmode
#endif
#ifdef _XBOX
#include <xtl.h>
#define INVALID_FILE_ATTRIBUTES -1
#else
#include <io.h>
#include <fcntl.h>
#include <direct.h>
#include <windows.h>
#endif
#elif defined(VITA)
#define SCE_ERROR_ERRNO_EEXIST 0x80010011
#include <psp2/io/fcntl.h>
#include <psp2/io/dirent.h>
#include <psp2/io/stat.h>
#else
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#endif
#if defined(PSP)
#include <pspkernel.h>
#endif
#ifdef __HAIKU__
#include <kernel/image.h>
#endif
#if (defined(__CELLOS_LV2__) && !defined(__PSL1GHT__)) || defined(__QNX__) || defined(PSP)
#include <unistd.h> /* stat() is defined here */
#endif
#include <file/file_path.h>
#include <compat/strl.h>
#include <compat/posix_string.h>
#include <retro_assert.h>
#include <retro_miscellaneous.h>
#if defined(__CELLOS_LV2__)
#ifndef S_ISDIR
#define S_ISDIR(x) (x & 0040000)
#endif
#endif
#if defined(VITA)
#define FIO_SO_ISDIR PSP2_S_ISDIR
#endif
/**
* path_is_directory:
* @path : path
*
* Checks if path is a directory.
*
* Returns: true (1) if path is a directory, otherwise false (0).
*/
bool path_is_directory(const char *path)
{
#if defined(VITA) || defined(PSP)
SceIoStat buf;
if (sceIoGetstat(path, &buf) < 0)
return false;
return FIO_SO_ISDIR(buf.st_mode);
#elif defined(__CELLOS_LV2__)
CellFsStat buf;
if (cellFsStat(path, &buf) < 0)
return false;
return ((buf.st_mode & S_IFMT) == S_IFDIR);
#elif defined(_WIN32)
DWORD ret = GetFileAttributes(path);
return (ret & FILE_ATTRIBUTE_DIRECTORY) && (ret != INVALID_FILE_ATTRIBUTES);
#else
struct stat buf;
if (stat(path, &buf) < 0)
return false;
return S_ISDIR(buf.st_mode);
#endif
}
/**
* path_mkdir_norecurse:
* @dir : directory
*
* Create directory on filesystem.
*
* Returns: true (1) if directory could be created, otherwise false (0).
**/
static bool path_mkdir_norecurse(const char *dir)
{
int ret;
#if defined(_WIN32)
ret = _mkdir(dir);
#elif defined(IOS)
ret = mkdir(dir, 0755);
#elif defined(VITA) || defined(PSP)
ret = sceIoMkdir(dir, 0777);
#else
ret = mkdir(dir, 0750);
#endif
/* Don't treat this as an error. */
#if defined(VITA)
if ((ret == SCE_ERROR_ERRNO_EEXIST) && path_is_directory(dir))
ret = 0;
#else
if (ret < 0 && errno == EEXIST && path_is_directory(dir))
ret = 0;
#endif
if (ret < 0)
printf("mkdir(%s) error: %s.\n", dir, strerror(errno));
return ret == 0;
}
/**
* path_mkdir:
* @dir : directory
*
* Create directory on filesystem.
*
* Returns: true (1) if directory could be created, otherwise false (0).
**/
bool path_mkdir(const char *dir)
{
const char *target = NULL;
/* Use heap. Real chance of stack overflow if we recurse too hard. */
char *basedir = strdup(dir);
bool ret = false;
if (!basedir)
return false;
path_parent_dir(basedir);
if (!*basedir || !strcmp(basedir, dir))
goto end;
if (path_is_directory(basedir))
{
target = dir;
ret = path_mkdir_norecurse(dir);
}
else
{
target = basedir;
ret = path_mkdir(basedir);
if (ret)
{
target = dir;
ret = path_mkdir_norecurse(dir);
}
}
end:
if (target && !ret)
printf("Failed to create directory: \"%s\".\n", target);
free(basedir);
return ret;
}
bool stat_is_valid(const char *path)
{
#if defined(VITA) || defined(PSP)
SceIoStat buf;
if (sceIoGetstat(path, &buf) < 0)
return false;
return true;
#elif defined(__CELLOS_LV2__)
CellFsStat buf;
if (cellFsStat(path, &buf) < 0)
return false;
return true;
#elif defined(_WIN32)
DWORD ret = GetFileAttributes(path);
return (ret != INVALID_FILE_ATTRIBUTES);
#else
struct stat buf;
if (stat(path, &buf) < 0)
return false;
return true;
#endif
}

View File

@ -74,18 +74,6 @@ bool path_is_compressed_file(const char *path);
**/
bool path_contains_compressed_file(const char *path);
/**
* path_is_directory:
* @path : path
*
* Checks if path is a directory.
*
* Returns: true (1) if path is a directory, otherwise false (0).
*/
bool path_is_directory(const char *path);
bool path_is_valid(const char *path);
/**
* path_file_exists:
* @path : path
@ -107,16 +95,6 @@ bool path_file_exists(const char *path);
*/
const char *path_get_extension(const char *path);
/**
* path_mkdir:
* @dir : directory
*
* Create directory on filesystem.
*
* Returns: true (1) if directory could be created, otherwise false (0).
**/
bool path_mkdir(const char *dir);
/**
* path_remove_extension:
* @path : path

View File

@ -0,0 +1,61 @@
/* Copyright (C) 2010-2015 The RetroArch team
*
* ---------------------------------------------------------------------------------------
* The following license statement only applies to this file (retro_stat.h).
* ---------------------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge,
* to any person obtaining a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef __RETRO_STAT_H
#define __RETRO_STAT_H
#include <stdint.h>
#include <stddef.h>
#include <boolean.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* path_mkdir:
* @dir : directory
*
* Create directory on filesystem.
*
* Returns: true (1) if directory could be created, otherwise false (0).
**/
bool path_mkdir(const char *dir);
/**
* path_is_directory:
* @path : path
*
* Checks if path is a directory.
*
* Returns: true (1) if path is a directory, otherwise false (0).
*/
bool path_is_directory(const char *path);
bool path_is_valid(const char *path);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -14,6 +14,7 @@
*/
#include <file/file_path.h>
#include <retro_stat.h>
#include "../menu.h"
#include "../menu_cbs.h"

View File

@ -5,7 +5,7 @@ LOCAL_MODULE := retroarch-jni
RARCH_DIR := ../../../..
LOCAL_CFLAGS += -std=gnu99 -Wall -DRARCH_DUMMY_LOG -DHAVE_ZLIB -DHAVE_MMAP -DRARCH_INTERNAL
LOCAL_LDLIBS := -llog -lz
LOCAL_SRC_FILES := apk-extract/apk-extract.c $(RARCH_DIR)/libretro-common/file/file_extract.c $(RARCH_DIR)/libretro-common/file/file_path.c $(RARCH_DIR)/file_ops.c $(RARCH_DIR)/libretro-common/string/string_list.c $(RARCH_DIR)/libretro-common/compat/compat.c $(RARCH_DIR)/libretro-common/file/retro_file.c
LOCAL_SRC_FILES := apk-extract/apk-extract.c $(RARCH_DIR)/libretro-common/file/file_extract.c $(RARCH_DIR)/libretro-common/file/file_path.c $(RARCH_DIR)/file_ops.c $(RARCH_DIR)/libretro-common/string/string_list.c $(RARCH_DIR)/libretro-common/compat/compat.c $(RARCH_DIR)/libretro-common/file/retro_file.c $(RARCH_DIR)/libretro-common/file/retro_stat.c
LOCAL_C_INCLUDES := $(LOCAL_PATH)/$(RARCH_DIR)/libretro-common/include/

View File

@ -5,6 +5,7 @@
#include <file/file_extract.h>
#include <file/file_path.h>
#include <retro_assert.h>
#include <retro_stat.h>
#include <retro_miscellaneous.h>
#include "../native/com_retroarch_browser_NativeInterface.h"

View File

@ -35,6 +35,7 @@
#include <compat/getopt.h>
#include <compat/posix_string.h>
#include <file/file_path.h>
#include <retro_stat.h>
#include "msg_hash.h"

View File

@ -22,6 +22,7 @@
#include <file/file_extract.h>
#include <net/net_compat.h>
#include <retro_file.h>
#include <retro_stat.h>
#include "../file_ops.h"
#include "../general.h"

View File

@ -22,6 +22,7 @@
#include "../libretro-common/dynamic/dylib.c"
#include "../libretro-common/file/retro_file.c"
#include "../libretro-common/file/retro_stat.c"
#if defined(__linux) && !defined(ANDROID)
#include "../input/drivers/linuxraw_input.c"