mirror of
https://github.com/libretro/RetroArch
synced 2025-02-28 12:40:23 +00:00
(file_path.c) Cleanups
This commit is contained in:
parent
e1041030a2
commit
ddb4867c52
@ -185,15 +185,47 @@ int32_t path_get_size(const char *path)
|
||||
}
|
||||
|
||||
/**
|
||||
* path_mkdir_norecurse:
|
||||
* path_mkdir:
|
||||
* @dir : directory
|
||||
*
|
||||
* Create directory on filesystem.
|
||||
*
|
||||
* Returns: true (1) if directory could be created, otherwise false (0).
|
||||
**/
|
||||
static bool mkdir_norecurse(const char *dir)
|
||||
bool path_mkdir(const char *dir)
|
||||
{
|
||||
/* Use heap. Real chance of stack overflow if we recurse too hard. */
|
||||
char *basedir = strdup(dir);
|
||||
const char *target = NULL;
|
||||
bool sret = false;
|
||||
bool norecurse = false;
|
||||
|
||||
if (!basedir)
|
||||
return false;
|
||||
|
||||
path_parent_dir(basedir);
|
||||
if (!*basedir || !strcmp(basedir, dir))
|
||||
goto end;
|
||||
|
||||
if (path_is_directory(basedir))
|
||||
{
|
||||
target = dir;
|
||||
norecurse = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
target = basedir;
|
||||
sret = path_mkdir(basedir);
|
||||
|
||||
if (sret)
|
||||
{
|
||||
target = dir;
|
||||
norecurse = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (norecurse)
|
||||
{
|
||||
#if defined(_WIN32)
|
||||
int ret = _mkdir(dir);
|
||||
#elif defined(IOS)
|
||||
@ -219,53 +251,14 @@ static bool mkdir_norecurse(const char *dir)
|
||||
#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 = mkdir_norecurse(dir);
|
||||
}
|
||||
else
|
||||
{
|
||||
target = basedir;
|
||||
ret = path_mkdir(basedir);
|
||||
|
||||
if (ret)
|
||||
{
|
||||
target = dir;
|
||||
ret = mkdir_norecurse(dir);
|
||||
}
|
||||
sret = (ret == 0);
|
||||
}
|
||||
|
||||
end:
|
||||
if (target && !ret)
|
||||
if (target && !sret)
|
||||
printf("Failed to create directory: \"%s\".\n", target);
|
||||
free(basedir);
|
||||
return ret;
|
||||
return sret;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -31,7 +31,6 @@
|
||||
#include <retro_common_api.h>
|
||||
|
||||
#include <boolean.h>
|
||||
#include <retro_inline.h>
|
||||
|
||||
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:
|
||||
|
Loading…
x
Reference in New Issue
Block a user