From ddb4867c52d6d5e6d8e4bcd557fb782b363e0ab6 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Wed, 28 Jun 2017 04:51:58 +0200 Subject: [PATCH] (file_path.c) Cleanups --- libretro-common/file/file_path.c | 91 +++++++++++------------- libretro-common/include/file/file_path.h | 15 ++-- 2 files changed, 46 insertions(+), 60 deletions(-) diff --git a/libretro-common/file/file_path.c b/libretro-common/file/file_path.c index 5c616b9007..b353627c59 100644 --- a/libretro-common/file/file_path.c +++ b/libretro-common/file/file_path.c @@ -184,44 +184,6 @@ int32_t path_get_size(const char *path) return -1; } -/** - * path_mkdir_norecurse: - * @dir : directory - * - * Create directory on filesystem. - * - * Returns: true (1) if directory could be created, otherwise false (0). - **/ -static 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 @@ -232,10 +194,11 @@ static bool mkdir_norecurse(const char *dir) **/ 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; + char *basedir = strdup(dir); + const char *target = NULL; + bool sret = false; + bool norecurse = false; if (!basedir) return false; @@ -246,26 +209,56 @@ bool path_mkdir(const char *dir) if (path_is_directory(basedir)) { - target = dir; - ret = mkdir_norecurse(dir); + target = dir; + norecurse = true; } else { target = basedir; - ret = path_mkdir(basedir); + sret = path_mkdir(basedir); - if (ret) + if (sret) { - target = dir; - ret = mkdir_norecurse(dir); + target = dir; + norecurse = true; } } + if (norecurse) + { +#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)); + sret = (ret == 0); + } + end: - if (target && !ret) + if (target && !sret) printf("Failed to create directory: \"%s\".\n", target); free(basedir); - return ret; + return sret; } /** diff --git a/libretro-common/include/file/file_path.h b/libretro-common/include/file/file_path.h index 2fcd947407..c92e35cf26 100644 --- a/libretro-common/include/file/file_path.h +++ b/libretro-common/include/file/file_path.h @@ -31,7 +31,6 @@ #include #include -#include RETRO_BEGIN_DECLS @@ -408,14 +407,11 @@ void fill_pathname_abbreviate_special(char *out_path, * * Returns: true (1) if character is a slash, otherwise false (0). */ -static INLINE bool path_char_is_slash(char c) -{ #ifdef _WIN32 - return (c == '/') || (c == '\\'); +#define path_char_is_slash(c) (((c) == '/') || ((c) == '\\')) #else - return (c == '/'); +#define path_char_is_slash(c) ((c) == '/') #endif -} /** * path_default_slash: @@ -424,14 +420,11 @@ static INLINE bool path_char_is_slash(char c) * * Returns: default slash separator. */ -static INLINE const char *path_default_slash(void) -{ #ifdef _WIN32 - return "\\"; +#define path_default_slash() "\\" #else - return "/"; +#define path_default_slash() "/" #endif -} /** * fill_pathname_slash: