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,14 +185,46 @@ int32_t path_get_size(const char *path)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* path_mkdir_norecurse:
|
* path_mkdir:
|
||||||
* @dir : directory
|
* @dir : directory
|
||||||
*
|
*
|
||||||
* Create directory on filesystem.
|
* Create directory on filesystem.
|
||||||
*
|
*
|
||||||
* Returns: true (1) if directory could be created, otherwise false (0).
|
* 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)
|
#if defined(_WIN32)
|
||||||
int ret = _mkdir(dir);
|
int ret = _mkdir(dir);
|
||||||
@ -219,53 +251,14 @@ static bool mkdir_norecurse(const char *dir)
|
|||||||
#endif
|
#endif
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
printf("mkdir(%s) error: %s.\n", dir, strerror(errno));
|
printf("mkdir(%s) error: %s.\n", dir, strerror(errno));
|
||||||
return ret == 0;
|
sret = (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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
end:
|
end:
|
||||||
if (target && !ret)
|
if (target && !sret)
|
||||||
printf("Failed to create directory: \"%s\".\n", target);
|
printf("Failed to create directory: \"%s\".\n", target);
|
||||||
free(basedir);
|
free(basedir);
|
||||||
return ret;
|
return sret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -31,7 +31,6 @@
|
|||||||
#include <retro_common_api.h>
|
#include <retro_common_api.h>
|
||||||
|
|
||||||
#include <boolean.h>
|
#include <boolean.h>
|
||||||
#include <retro_inline.h>
|
|
||||||
|
|
||||||
RETRO_BEGIN_DECLS
|
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).
|
* Returns: true (1) if character is a slash, otherwise false (0).
|
||||||
*/
|
*/
|
||||||
static INLINE bool path_char_is_slash(char c)
|
|
||||||
{
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
return (c == '/') || (c == '\\');
|
#define path_char_is_slash(c) (((c) == '/') || ((c) == '\\'))
|
||||||
#else
|
#else
|
||||||
return (c == '/');
|
#define path_char_is_slash(c) ((c) == '/')
|
||||||
#endif
|
#endif
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* path_default_slash:
|
* path_default_slash:
|
||||||
@ -424,14 +420,11 @@ static INLINE bool path_char_is_slash(char c)
|
|||||||
*
|
*
|
||||||
* Returns: default slash separator.
|
* Returns: default slash separator.
|
||||||
*/
|
*/
|
||||||
static INLINE const char *path_default_slash(void)
|
|
||||||
{
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
return "\\";
|
#define path_default_slash() "\\"
|
||||||
#else
|
#else
|
||||||
return "/";
|
#define path_default_slash() "/"
|
||||||
#endif
|
#endif
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* fill_pathname_slash:
|
* fill_pathname_slash:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user