From 6af5bd01bfb76b66258b8e747dd173e1cead6546 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Fri, 16 Jun 2017 15:00:11 +0200 Subject: [PATCH] Merge retro_stat and file_path --- Makefile.common | 1 - camera/drivers/video4linux2.c | 2 +- configuration.c | 1 - core_info.c | 2 - dirs.c | 1 - frontend/drivers/platform_emscripten.c | 1 - frontend/drivers/platform_linux.c | 1 - griffin/griffin.c | 1 - libretro-common/file/archive_file.c | 1 - libretro-common/file/config_file.c | 1 - libretro-common/file/file_path.c | 190 ++++++++++++++++++- libretro-common/file/retro_dirent.c | 2 +- libretro-common/file/retro_stat.c | 214 ---------------------- libretro-common/include/file/file_path.h | 26 +++ libretro-common/include/retro_stat.h | 63 ------- menu/cbs/menu_cbs_ok.c | 1 - menu/drivers/nuklear/nk_wnd_file_picker.c | 1 - menu/drivers/zarch.c | 1 - menu/menu_content.c | 1 - menu/menu_displaylist.c | 1 - paths.c | 1 - retroarch.c | 1 - tasks/task_content.c | 1 - tasks/task_decompress.c | 1 - tasks/task_http.c | 1 - tasks/task_patch.c | 1 - 26 files changed, 215 insertions(+), 303 deletions(-) delete mode 100644 libretro-common/file/retro_stat.c delete mode 100644 libretro-common/include/retro_stat.h diff --git a/Makefile.common b/Makefile.common index 51f5b44c30ff..786b491a2b23 100644 --- a/Makefile.common +++ b/Makefile.common @@ -174,7 +174,6 @@ OBJ += frontend/frontend.o \ $(LIBRETRO_COMM_DIR)/streams/file_stream.o \ $(LIBRETRO_COMM_DIR)/streams/interface_stream.o \ $(LIBRETRO_COMM_DIR)/streams/memory_stream.o \ - $(LIBRETRO_COMM_DIR)/file/retro_stat.o \ $(LIBRETRO_COMM_DIR)/lists/string_list.o \ $(LIBRETRO_COMM_DIR)/string/stdstring.o \ $(LIBRETRO_COMM_DIR)/memmap/memalign.o \ diff --git a/camera/drivers/video4linux2.c b/camera/drivers/video4linux2.c index 9cd881cdeda3..20960d0b166d 100644 --- a/camera/drivers/video4linux2.c +++ b/camera/drivers/video4linux2.c @@ -37,7 +37,7 @@ #include #include #include -#include +#include #include diff --git a/configuration.c b/configuration.c index 0cb6d54b7389..a1c4b5eab780 100644 --- a/configuration.c +++ b/configuration.c @@ -22,7 +22,6 @@ #include #include #include -#include #include #include diff --git a/core_info.c b/core_info.c index 7ab95ba2c139..117b2394f6f4 100644 --- a/core_info.c +++ b/core_info.c @@ -21,8 +21,6 @@ #include #include -#include - #ifdef HAVE_CONFIG_H #include "config.h" #endif diff --git a/dirs.c b/dirs.c index ce484e86b5d6..3835dde1ef77 100644 --- a/dirs.c +++ b/dirs.c @@ -20,7 +20,6 @@ #include #include #include -#include #include "dirs.h" #include "command.h" diff --git a/frontend/drivers/platform_emscripten.c b/frontend/drivers/platform_emscripten.c index 9784ece3cd2a..333759677358 100644 --- a/frontend/drivers/platform_emscripten.c +++ b/frontend/drivers/platform_emscripten.c @@ -20,7 +20,6 @@ #include #include -#include #include #include diff --git a/frontend/drivers/platform_linux.c b/frontend/drivers/platform_linux.c index 5cbeecfe7ba1..298ee7393d4c 100644 --- a/frontend/drivers/platform_linux.c +++ b/frontend/drivers/platform_linux.c @@ -46,7 +46,6 @@ #include #include #include -#include #include #include #include diff --git a/griffin/griffin.c b/griffin/griffin.c index 5b3fd5b4178c..360421561d33 100644 --- a/griffin/griffin.c +++ b/griffin/griffin.c @@ -736,7 +736,6 @@ FILE #include "../libretro-common/streams/file_stream.c" #include "../libretro-common/streams/interface_stream.c" #include "../libretro-common/streams/memory_stream.c" -#include "../libretro-common/file/retro_stat.c" #include "../list_special.c" #include "../libretro-common/string/stdstring.c" #include "../libretro-common/file/nbio/nbio_stdio.c" diff --git a/libretro-common/file/archive_file.c b/libretro-common/file/archive_file.c index 1e300238e9d5..4a110451155a 100644 --- a/libretro-common/file/archive_file.c +++ b/libretro-common/file/archive_file.c @@ -42,7 +42,6 @@ #include #include #include -#include #include #include #include diff --git a/libretro-common/file/config_file.c b/libretro-common/file/config_file.c index 3c55fce14765..db5c87c988de 100644 --- a/libretro-common/file/config_file.c +++ b/libretro-common/file/config_file.c @@ -41,7 +41,6 @@ #include #include #include -#include #include #include #include diff --git a/libretro-common/file/file_path.c b/libretro-common/file/file_path.c index 7438cd51d136..edd113787b80 100644 --- a/libretro-common/file/file_path.c +++ b/libretro-common/file/file_path.c @@ -20,14 +20,15 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +#include #include -#include #include #include #include #include +#include #include #ifndef __MACH__ @@ -36,10 +37,193 @@ #endif #include #include -#include #include #include +#if defined(_WIN32) +#ifdef _MSC_VER +#define setmode _setmode +#endif +#include +#ifdef _XBOX +#include +#define INVALID_FILE_ATTRIBUTES -1 +#else +#include +#include +#include +#include +#endif +#elif defined(VITA) +#define SCE_ERROR_ERRNO_EEXIST 0x80010011 +#include +#include +#include +#else +#include +#include +#include +#endif + +#if defined(PSP) +#include +#endif + +#ifdef __HAIKU__ +#include +#endif + +#if defined(__CELLOS_LV2__) +#include +#endif + +#if defined(VITA) +#define FIO_S_ISDIR SCE_S_ISDIR +#endif + +#if (defined(__CELLOS_LV2__) && !defined(__PSL1GHT__)) || defined(__QNX__) || defined(PSP) +#include /* stat() is defined here */ +#endif + +enum stat_mode +{ + IS_DIRECTORY = 0, + IS_CHARACTER_SPECIAL, + IS_VALID +}; + +static bool path_stat(const char *path, enum stat_mode mode, int32_t *size) +{ +#if defined(VITA) || defined(PSP) + SceIoStat buf; + char *tmp = strdup(path); + size_t len = strlen(tmp); + if (tmp[len-1] == '/') + tmp[len-1]='\0'; + + if (sceIoGetstat(tmp, &buf) < 0) + { + free(tmp); + return false; + } + free(tmp); + +#elif defined(__CELLOS_LV2__) + CellFsStat buf; + if (cellFsStat(path, &buf) < 0) + return false; +#elif defined(_WIN32) + struct _stat buf; + DWORD file_info = GetFileAttributes(path); + + _stat(path, &buf); + + if (file_info == INVALID_FILE_ATTRIBUTES) + return false; +#else + struct stat buf; + if (stat(path, &buf) < 0) + return false; +#endif + + if (size) + *size = (int32_t)buf.st_size; + + switch (mode) + { + case IS_DIRECTORY: +#if defined(VITA) || defined(PSP) + return FIO_S_ISDIR(buf.st_mode); +#elif defined(__CELLOS_LV2__) + return ((buf.st_mode & S_IFMT) == S_IFDIR); +#elif defined(_WIN32) + return (file_info & FILE_ATTRIBUTE_DIRECTORY); +#else + return S_ISDIR(buf.st_mode); +#endif + case IS_CHARACTER_SPECIAL: +#if defined(VITA) || defined(PSP) || defined(__CELLOS_LV2__) || defined(_WIN32) + return false; +#else + return S_ISCHR(buf.st_mode); +#endif + case IS_VALID: + return true; + } + + 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) +{ + return path_stat(path, IS_DIRECTORY, NULL); +} + +bool path_is_character_special(const char *path) +{ + return path_stat(path, IS_CHARACTER_SPECIAL, NULL); +} + +bool path_is_valid(const char *path) +{ + return path_stat(path, IS_VALID, NULL); +} + +int32_t path_get_size(const char *path) +{ + int32_t filesize = 0; + if (path_stat(path, IS_VALID, &filesize)) + return filesize; + + return -1; +} + +/** + * path_mkdir_norecurse: + * @dir : directory + * + * Create directory on filesystem. + * + * Returns: true (1) if directory could be created, otherwise false (0). + **/ +bool mkdir_norecurse(const char *dir) +{ +#if defined(_WIN32) + int ret = _mkdir(dir); +#elif defined(IOS) + int ret = mkdir(dir, 0755); +#elif defined(VITA) || defined(PSP) + int ret = sceIoMkdir(dir, 0777); +#elif defined(__QNX__) + int ret = mkdir(dir, 0777); +#else + int 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; +#elif defined(PSP) || defined(_3DS) || defined(WIIU) + if ((ret == -1) && 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 @@ -98,7 +282,7 @@ bool path_mkdir(const char *dir) */ const char *path_get_archive_delim(const char *path) { - const char *last = find_last_slash(path); + const char *last = find_last_slash(path); const char *delim = NULL; if (last) diff --git a/libretro-common/file/retro_dirent.c b/libretro-common/file/retro_dirent.c index 66830a0bd7b9..6afa37e46237 100644 --- a/libretro-common/file/retro_dirent.c +++ b/libretro-common/file/retro_dirent.c @@ -26,7 +26,7 @@ #include #include -#include +#include #include #include diff --git a/libretro-common/file/retro_stat.c b/libretro-common/file/retro_stat.c deleted file mode 100644 index 56a9b41b348c..000000000000 --- a/libretro-common/file/retro_stat.c +++ /dev/null @@ -1,214 +0,0 @@ -/* Copyright (C) 2010-2017 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 -#include -#include -#include -#include - -#if defined(_WIN32) -#ifdef _MSC_VER -#define setmode _setmode -#endif -#include -#ifdef _XBOX -#include -#define INVALID_FILE_ATTRIBUTES -1 -#else -#include -#include -#include -#include -#endif -#elif defined(VITA) -#define SCE_ERROR_ERRNO_EEXIST 0x80010011 -#include -#include -#include -#else -#include -#include -#include -#endif - -#if defined(PSP) -#include -#endif - -#ifdef __HAIKU__ -#include -#endif - -#if defined(__CELLOS_LV2__) -#include -#endif - -#if defined(VITA) -#define FIO_S_ISDIR SCE_S_ISDIR -#endif - -#if (defined(__CELLOS_LV2__) && !defined(__PSL1GHT__)) || defined(__QNX__) || defined(PSP) -#include /* stat() is defined here */ -#endif - -#include -#include - -enum stat_mode -{ - IS_DIRECTORY = 0, - IS_CHARACTER_SPECIAL, - IS_VALID -}; - -static bool path_stat(const char *path, enum stat_mode mode, int32_t *size) -{ -#if defined(VITA) || defined(PSP) - SceIoStat buf; - char *tmp = strdup(path); - size_t len = strlen(tmp); - if (tmp[len-1] == '/') - tmp[len-1]='\0'; - - if (sceIoGetstat(tmp, &buf) < 0) - { - free(tmp); - return false; - } - free(tmp); - -#elif defined(__CELLOS_LV2__) - CellFsStat buf; - if (cellFsStat(path, &buf) < 0) - return false; -#elif defined(_WIN32) - DWORD file_info = GetFileAttributes(path); - struct _stat buf; - - _stat(path, &buf); - - if (file_info == INVALID_FILE_ATTRIBUTES) - return false; -#else - struct stat buf; - if (stat(path, &buf) < 0) - return false; -#endif - - if (size) - *size = (int32_t)buf.st_size; - - switch (mode) - { - case IS_DIRECTORY: -#if defined(VITA) || defined(PSP) - return FIO_S_ISDIR(buf.st_mode); -#elif defined(__CELLOS_LV2__) - return ((buf.st_mode & S_IFMT) == S_IFDIR); -#elif defined(_WIN32) - return (file_info & FILE_ATTRIBUTE_DIRECTORY); -#else - return S_ISDIR(buf.st_mode); -#endif - case IS_CHARACTER_SPECIAL: -#if defined(VITA) || defined(PSP) || defined(__CELLOS_LV2__) || defined(_WIN32) - return false; -#else - return S_ISCHR(buf.st_mode); -#endif - case IS_VALID: - return true; - } - - 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) -{ - return path_stat(path, IS_DIRECTORY, NULL); -} - -bool path_is_character_special(const char *path) -{ - return path_stat(path, IS_CHARACTER_SPECIAL, NULL); -} - -bool path_is_valid(const char *path) -{ - return path_stat(path, IS_VALID, NULL); -} - -int32_t path_get_size(const char *path) -{ - int32_t filesize = 0; - if (path_stat(path, IS_VALID, &filesize)) - return filesize; - - return -1; -} - -/** - * path_mkdir_norecurse: - * @dir : directory - * - * Create directory on filesystem. - * - * Returns: true (1) if directory could be created, otherwise false (0). - **/ -bool 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); -#elif defined(__QNX__) - ret = mkdir(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; -#elif defined(PSP) || defined(_3DS) || defined(WIIU) - if ((ret == -1) && 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; -} diff --git a/libretro-common/include/file/file_path.h b/libretro-common/include/file/file_path.h index 1a56242e7766..ab1c10a4b2ee 100644 --- a/libretro-common/include/file/file_path.h +++ b/libretro-common/include/file/file_path.h @@ -457,6 +457,32 @@ void fill_pathname_application_path(char *buf, size_t size); **/ 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_character_special(const char *path); + +bool path_is_valid(const char *path); + +int32_t path_get_size(const char *path); + +/** + * path_mkdir_norecurse: + * @dir : directory + * + * Create directory on filesystem. + * + * Returns: true (1) if directory could be created, otherwise false (0). + **/ +bool mkdir_norecurse(const char *dir); + RETRO_END_DECLS #endif diff --git a/libretro-common/include/retro_stat.h b/libretro-common/include/retro_stat.h deleted file mode 100644 index b5b24a47c1df..000000000000 --- a/libretro-common/include/retro_stat.h +++ /dev/null @@ -1,63 +0,0 @@ -/* Copyright (C) 2010-2017 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 -#include - -#include - -#include - -RETRO_BEGIN_DECLS - -/** - * 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_character_special(const char *path); - -bool path_is_valid(const char *path); - -int32_t path_get_size(const char *path); - -/** - * path_mkdir_norecurse: - * @dir : directory - * - * Create directory on filesystem. - * - * Returns: true (1) if directory could be created, otherwise false (0). - **/ -bool mkdir_norecurse(const char *dir); - -RETRO_END_DECLS - -#endif diff --git a/menu/cbs/menu_cbs_ok.c b/menu/cbs/menu_cbs_ok.c index 6271e06519c9..6971af2ca49b 100644 --- a/menu/cbs/menu_cbs_ok.c +++ b/menu/cbs/menu_cbs_ok.c @@ -17,7 +17,6 @@ #include #include #include -#include #include #include #include diff --git a/menu/drivers/nuklear/nk_wnd_file_picker.c b/menu/drivers/nuklear/nk_wnd_file_picker.c index 09467cc75833..965da78fb37b 100644 --- a/menu/drivers/nuklear/nk_wnd_file_picker.c +++ b/menu/drivers/nuklear/nk_wnd_file_picker.c @@ -25,7 +25,6 @@ #include #include #include -#include #include "nk_menu.h" diff --git a/menu/drivers/zarch.c b/menu/drivers/zarch.c index 3a7055a218d1..11f97aaa3db7 100644 --- a/menu/drivers/zarch.c +++ b/menu/drivers/zarch.c @@ -29,7 +29,6 @@ #include #include #include -#include #include #include "menu_generic.h" diff --git a/menu/menu_content.c b/menu/menu_content.c index ec4d28b0374b..82b9bc357039 100644 --- a/menu/menu_content.c +++ b/menu/menu_content.c @@ -17,7 +17,6 @@ #include #include #include -#include #include #ifdef HAVE_CONFIG_H diff --git a/menu/menu_displaylist.c b/menu/menu_displaylist.c index ac8a62e0cc5b..de16b1fde8c1 100644 --- a/menu/menu_displaylist.c +++ b/menu/menu_displaylist.c @@ -24,7 +24,6 @@ #include #include #include -#include #include #include diff --git a/paths.c b/paths.c index fd36464cc4d3..c820e0027fb2 100644 --- a/paths.c +++ b/paths.c @@ -19,7 +19,6 @@ #include #include #include -#include #ifdef HAVE_CONFIG_H #include "config.h" diff --git a/retroarch.c b/retroarch.c index e1573a27b687..6d61e6d6bdd0 100644 --- a/retroarch.c +++ b/retroarch.c @@ -42,7 +42,6 @@ #include