mirror of
https://github.com/libretro/RetroArch
synced 2025-04-07 13:23:32 +00:00
(file_path.c) Small simplifications
This commit is contained in:
parent
c9caa5c39b
commit
fb653d22dc
@ -195,15 +195,18 @@ int32_t path_get_size(const char *path)
|
|||||||
**/
|
**/
|
||||||
bool path_mkdir(const char *dir)
|
bool path_mkdir(const char *dir)
|
||||||
{
|
{
|
||||||
/* Use heap. Real chance of stack overflow if we recurse too hard. */
|
|
||||||
bool sret = false;
|
bool sret = false;
|
||||||
bool norecurse = false;
|
bool norecurse = false;
|
||||||
char *basedir = (dir && *dir) ? strdup(dir) : NULL;
|
char *basedir = NULL;
|
||||||
|
|
||||||
if (!basedir)
|
if (!(dir && *dir))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
/* Use heap. Real chance of stack
|
||||||
|
* overflow if we recurse too hard. */
|
||||||
|
basedir = strdup(dir);
|
||||||
path_parent_dir(basedir);
|
path_parent_dir(basedir);
|
||||||
|
|
||||||
if (!*basedir || !strcmp(basedir, dir))
|
if (!*basedir || !strcmp(basedir, dir))
|
||||||
{
|
{
|
||||||
free(basedir);
|
free(basedir);
|
||||||
@ -251,19 +254,20 @@ 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;
|
const char *delim = NULL;
|
||||||
|
|
||||||
if (last)
|
if (!last)
|
||||||
{
|
return NULL;
|
||||||
delim = strcasestr(last, ".zip#");
|
|
||||||
|
|
||||||
if (!delim)
|
/* Test if it's .zip */
|
||||||
delim = strcasestr(last, ".apk#");
|
delim = strcasestr(last, ".zip#");
|
||||||
}
|
|
||||||
|
if (!delim) /* If it's not a .zip, test if it's .apk */
|
||||||
|
delim = strcasestr(last, ".apk#");
|
||||||
|
|
||||||
if (delim)
|
if (delim)
|
||||||
return delim + 4;
|
return delim + 4;
|
||||||
|
|
||||||
if (last)
|
/* If it's not a .zip or .apk file, test if it's .7z */
|
||||||
delim = strcasestr(last, ".7z#");
|
delim = strcasestr(last, ".7z#");
|
||||||
|
|
||||||
if (delim)
|
if (delim)
|
||||||
return delim + 3;
|
return delim + 3;
|
||||||
@ -414,11 +418,18 @@ char *find_last_slash(const char *str)
|
|||||||
**/
|
**/
|
||||||
void fill_pathname_slash(char *path, size_t size)
|
void fill_pathname_slash(char *path, size_t size)
|
||||||
{
|
{
|
||||||
size_t path_len = strlen(path);
|
size_t path_len;
|
||||||
const char *last_slash = find_last_slash(path);
|
const char *last_slash = find_last_slash(path);
|
||||||
|
|
||||||
|
if (!last_slash)
|
||||||
|
{
|
||||||
|
strlcat(path, path_default_slash(), size);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
path_len = strlen(path);
|
||||||
/* Try to preserve slash type. */
|
/* Try to preserve slash type. */
|
||||||
if (last_slash && (last_slash != (path + path_len - 1)))
|
if (last_slash != (path + path_len - 1))
|
||||||
{
|
{
|
||||||
char join_str[2];
|
char join_str[2];
|
||||||
|
|
||||||
@ -427,8 +438,6 @@ void fill_pathname_slash(char *path, size_t size)
|
|||||||
strlcpy(join_str, last_slash, sizeof(join_str));
|
strlcpy(join_str, last_slash, sizeof(join_str));
|
||||||
strlcat(path, join_str, size);
|
strlcat(path, join_str, size);
|
||||||
}
|
}
|
||||||
else if (!last_slash)
|
|
||||||
strlcat(path, path_default_slash(), size);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user