From 385e030261693f41fa70ed382c791e36a878fddd Mon Sep 17 00:00:00 2001 From: twinaphex Date: Tue, 22 Sep 2015 19:34:16 +0200 Subject: [PATCH] Move functions around --- libretro-common/file/file_path.c | 50 +++++++++++++++++++ libretro-common/file/retro_stat.c | 63 ++++-------------------- libretro-common/include/file/file_path.h | 10 ++++ libretro-common/include/retro_stat.h | 20 ++++---- 4 files changed, 79 insertions(+), 64 deletions(-) diff --git a/libretro-common/file/file_path.c b/libretro-common/file/file_path.c index 7b5d7f21ee..312944ac68 100644 --- a/libretro-common/file/file_path.c +++ b/libretro-common/file/file_path.c @@ -31,13 +31,63 @@ #include #endif +#include + #include #include #include #include +#include #include + +/** + * 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 = mkdir_norecurse(dir); + } + else + { + target = basedir; + ret = path_mkdir(basedir); + + if (ret) + { + target = dir; + ret = mkdir_norecurse(dir); + } + } + +end: + if (target && !ret) + printf("Failed to create directory: \"%s\".\n", target); + free(basedir); + return ret; +} + /** * path_get_extension: * @path : path diff --git a/libretro-common/file/retro_stat.c b/libretro-common/file/retro_stat.c index 63e33a42b9..49ac1e86bb 100644 --- a/libretro-common/file/retro_stat.c +++ b/libretro-common/file/retro_stat.c @@ -20,6 +20,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +#include #include #include #include @@ -56,13 +57,6 @@ #include #endif -#if (defined(__CELLOS_LV2__) && !defined(__PSL1GHT__)) || defined(__QNX__) || defined(PSP) -#include /* stat() is defined here */ -#endif - -#include -#include - #if defined(__CELLOS_LV2__) #include #endif @@ -71,6 +65,13 @@ #define FIO_SO_ISDIR PSP2_S_ISDIR #endif +#if (defined(__CELLOS_LV2__) && !defined(__PSL1GHT__)) || defined(__QNX__) || defined(PSP) +#include /* stat() is defined here */ +#endif + +#include +#include + /** * path_is_directory: * @path : path @@ -111,7 +112,7 @@ bool path_is_directory(const char *path) * * Returns: true (1) if directory could be created, otherwise false (0). **/ -static bool path_mkdir_norecurse(const char *dir) +bool mkdir_norecurse(const char *dir) { int ret; #if defined(_WIN32) @@ -136,52 +137,6 @@ static bool path_mkdir_norecurse(const char *dir) 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) diff --git a/libretro-common/include/file/file_path.h b/libretro-common/include/file/file_path.h index a8dea55515..62a4d3ab2a 100644 --- a/libretro-common/include/file/file_path.h +++ b/libretro-common/include/file/file_path.h @@ -379,6 +379,16 @@ void fill_pathname_slash(char *path, size_t size); void fill_pathname_application_path(char *buf, size_t size); #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); + #ifdef __cplusplus } #endif diff --git a/libretro-common/include/retro_stat.h b/libretro-common/include/retro_stat.h index 0df2df58b3..1682c1ad44 100644 --- a/libretro-common/include/retro_stat.h +++ b/libretro-common/include/retro_stat.h @@ -28,16 +28,6 @@ #include -/** - * 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 @@ -50,4 +40,14 @@ bool path_is_directory(const char *path); bool path_is_valid(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); + #endif