mirror of
https://github.com/libretro/RetroArch
synced 2025-04-07 13:23:32 +00:00
libretro-common: Clean up dependencies of file_path
This moves a few functions that were defined in file_path_special to libretro-common to clean up the dependency tree.
This commit is contained in:
parent
728f77b2bc
commit
26b9cb3c78
@ -65,118 +65,6 @@
|
|||||||
#include "paths.h"
|
#include "paths.h"
|
||||||
#include "verbosity.h"
|
#include "verbosity.h"
|
||||||
|
|
||||||
void fill_pathname_expand_special(char *out_path,
|
|
||||||
const char *in_path, size_t size)
|
|
||||||
{
|
|
||||||
#if !defined(RARCH_CONSOLE)
|
|
||||||
if (*in_path == '~')
|
|
||||||
{
|
|
||||||
const char *home = getenv("HOME");
|
|
||||||
if (home)
|
|
||||||
{
|
|
||||||
size_t src_size = strlcpy(out_path, home, size);
|
|
||||||
retro_assert(src_size < size);
|
|
||||||
|
|
||||||
out_path += src_size;
|
|
||||||
size -= src_size;
|
|
||||||
in_path++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if ((in_path[0] == ':') &&
|
|
||||||
(
|
|
||||||
(in_path[1] == '/')
|
|
||||||
#ifdef _WIN32
|
|
||||||
|| (in_path[1] == '\\')
|
|
||||||
#endif
|
|
||||||
)
|
|
||||||
)
|
|
||||||
{
|
|
||||||
size_t src_size;
|
|
||||||
char *application_dir = (char*)malloc(PATH_MAX_LENGTH * sizeof(char));
|
|
||||||
|
|
||||||
application_dir[0] = '\0';
|
|
||||||
|
|
||||||
fill_pathname_application_path(application_dir,
|
|
||||||
PATH_MAX_LENGTH * sizeof(char));
|
|
||||||
path_basedir_wrapper(application_dir);
|
|
||||||
|
|
||||||
src_size = strlcpy(out_path, application_dir, size);
|
|
||||||
retro_assert(src_size < size);
|
|
||||||
|
|
||||||
free(application_dir);
|
|
||||||
|
|
||||||
out_path += src_size;
|
|
||||||
size -= src_size;
|
|
||||||
in_path += 2;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
retro_assert(strlcpy(out_path, in_path, size) < size);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void fill_pathname_abbreviate_special(char *out_path,
|
|
||||||
const char *in_path, size_t size)
|
|
||||||
{
|
|
||||||
#if !defined(RARCH_CONSOLE)
|
|
||||||
unsigned i;
|
|
||||||
const char *candidates[3];
|
|
||||||
const char *notations[3];
|
|
||||||
char *application_dir = (char*)malloc(PATH_MAX_LENGTH * sizeof(char));
|
|
||||||
const char *home = getenv("HOME");
|
|
||||||
|
|
||||||
application_dir[0] = '\0';
|
|
||||||
|
|
||||||
/* application_dir could be zero-string. Safeguard against this.
|
|
||||||
*
|
|
||||||
* Keep application dir in front of home, moving app dir to a
|
|
||||||
* new location inside home would break otherwise. */
|
|
||||||
|
|
||||||
/* ugly hack - use application_dir pointer
|
|
||||||
* before filling it in. C89 reasons */
|
|
||||||
candidates[0] = application_dir;
|
|
||||||
candidates[1] = home;
|
|
||||||
candidates[2] = NULL;
|
|
||||||
|
|
||||||
notations [0] = ":";
|
|
||||||
notations [1] = "~";
|
|
||||||
notations [2] = NULL;
|
|
||||||
|
|
||||||
fill_pathname_application_path(application_dir,
|
|
||||||
PATH_MAX_LENGTH * sizeof(char));
|
|
||||||
path_basedir_wrapper(application_dir);
|
|
||||||
|
|
||||||
for (i = 0; candidates[i]; i++)
|
|
||||||
{
|
|
||||||
if (!string_is_empty(candidates[i]) &&
|
|
||||||
strstr(in_path, candidates[i]) == in_path)
|
|
||||||
{
|
|
||||||
size_t src_size = strlcpy(out_path, notations[i], size);
|
|
||||||
|
|
||||||
retro_assert(src_size < size);
|
|
||||||
|
|
||||||
out_path += src_size;
|
|
||||||
size -= src_size;
|
|
||||||
in_path += strlen(candidates[i]);
|
|
||||||
|
|
||||||
if (!path_char_is_slash(*in_path))
|
|
||||||
{
|
|
||||||
retro_assert(strlcpy(out_path,
|
|
||||||
path_default_slash(), size) < size);
|
|
||||||
out_path++;
|
|
||||||
size--;
|
|
||||||
}
|
|
||||||
|
|
||||||
break; /* Don't allow more abbrevs to take place. */
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
free(application_dir);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
retro_assert(strlcpy(out_path, in_path, size) < size);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool fill_pathname_application_data(char *s, size_t len)
|
bool fill_pathname_application_data(char *s, size_t len)
|
||||||
{
|
{
|
||||||
#if defined(_WIN32) && !defined(_XBOX)
|
#if defined(_WIN32) && !defined(_XBOX)
|
||||||
@ -240,103 +128,6 @@ bool fill_pathname_application_data(char *s, size_t len)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !defined(RARCH_CONSOLE)
|
|
||||||
void fill_pathname_application_path(char *s, size_t len)
|
|
||||||
{
|
|
||||||
size_t i;
|
|
||||||
#ifdef __APPLE__
|
|
||||||
CFBundleRef bundle = CFBundleGetMainBundle();
|
|
||||||
#endif
|
|
||||||
#ifdef _WIN32
|
|
||||||
DWORD ret;
|
|
||||||
wchar_t wstr[PATH_MAX_LENGTH] = {0};
|
|
||||||
#endif
|
|
||||||
#ifdef __HAIKU__
|
|
||||||
image_info info;
|
|
||||||
int32_t cookie = 0;
|
|
||||||
#endif
|
|
||||||
(void)i;
|
|
||||||
|
|
||||||
if (!len)
|
|
||||||
return;
|
|
||||||
|
|
||||||
#ifdef _WIN32
|
|
||||||
#ifdef LEGACY_WIN32
|
|
||||||
ret = GetModuleFileNameA(GetModuleHandle(NULL), s, len);
|
|
||||||
#else
|
|
||||||
ret = GetModuleFileNameW(GetModuleHandle(NULL), wstr, ARRAY_SIZE(wstr));
|
|
||||||
|
|
||||||
if (*wstr)
|
|
||||||
{
|
|
||||||
char *str = utf16_to_utf8_string_alloc(wstr);
|
|
||||||
|
|
||||||
if (str)
|
|
||||||
{
|
|
||||||
strlcpy(s, str, len);
|
|
||||||
free(str);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
s[ret] = '\0';
|
|
||||||
#elif defined(__APPLE__)
|
|
||||||
if (bundle)
|
|
||||||
{
|
|
||||||
CFURLRef bundle_url = CFBundleCopyBundleURL(bundle);
|
|
||||||
CFStringRef bundle_path = CFURLCopyPath(bundle_url);
|
|
||||||
CFStringGetCString(bundle_path, s, len, kCFStringEncodingUTF8);
|
|
||||||
CFRelease(bundle_path);
|
|
||||||
CFRelease(bundle_url);
|
|
||||||
|
|
||||||
retro_assert(strlcat(s, "nobin", len) < len);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
#elif defined(__HAIKU__)
|
|
||||||
while (get_next_image_info(0, &cookie, &info) == B_OK)
|
|
||||||
{
|
|
||||||
if (info.type == B_APP_IMAGE)
|
|
||||||
{
|
|
||||||
strlcpy(s, info.name, len);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#elif defined(__QNX__)
|
|
||||||
char *buff = malloc(len);
|
|
||||||
|
|
||||||
if(_cmdname(buff))
|
|
||||||
strlcpy(s, buff, len);
|
|
||||||
|
|
||||||
free(buff);
|
|
||||||
#else
|
|
||||||
{
|
|
||||||
pid_t pid;
|
|
||||||
static const char *exts[] = { "exe", "file", "path/a.out" };
|
|
||||||
char link_path[255];
|
|
||||||
|
|
||||||
link_path[0] = *s = '\0';
|
|
||||||
pid = getpid();
|
|
||||||
|
|
||||||
/* Linux, BSD and Solaris paths. Not standardized. */
|
|
||||||
for (i = 0; i < ARRAY_SIZE(exts); i++)
|
|
||||||
{
|
|
||||||
ssize_t ret;
|
|
||||||
|
|
||||||
snprintf(link_path, sizeof(link_path), "/proc/%u/%s",
|
|
||||||
(unsigned)pid, exts[i]);
|
|
||||||
ret = readlink(link_path, s, len - 1);
|
|
||||||
|
|
||||||
if (ret >= 0)
|
|
||||||
{
|
|
||||||
s[ret] = '\0';
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
RARCH_ERR("Cannot resolve application path! This should not happen.\n");
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef HAVE_XMB
|
#ifdef HAVE_XMB
|
||||||
const char* xmb_theme_ident(void);
|
const char* xmb_theme_ident(void);
|
||||||
#endif
|
#endif
|
||||||
@ -626,31 +417,3 @@ void fill_short_pathname_representation_wrapper(char* out_rep,
|
|||||||
fill_short_pathname_representation(out_rep, in_path, size);
|
fill_short_pathname_representation(out_rep, in_path, size);
|
||||||
free(path_short);
|
free(path_short);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* path_basedir:
|
|
||||||
* @path : path
|
|
||||||
*
|
|
||||||
* Extracts base directory by mutating path.
|
|
||||||
* Keeps trailing '/'.
|
|
||||||
**/
|
|
||||||
void path_basedir_wrapper(char *path)
|
|
||||||
{
|
|
||||||
char *last = NULL;
|
|
||||||
if (strlen(path) < 2)
|
|
||||||
return;
|
|
||||||
|
|
||||||
#ifdef HAVE_COMPRESSION
|
|
||||||
/* We want to find the directory with the archive in basedir. */
|
|
||||||
last = (char*)path_get_archive_delim(path);
|
|
||||||
if (last)
|
|
||||||
*last = '\0';
|
|
||||||
#endif
|
|
||||||
|
|
||||||
last = find_last_slash(path);
|
|
||||||
|
|
||||||
if (last)
|
|
||||||
last[1] = '\0';
|
|
||||||
else
|
|
||||||
snprintf(path, 3, ".%s", path_default_slash());
|
|
||||||
}
|
|
||||||
|
@ -130,15 +130,6 @@ enum application_special_type
|
|||||||
void fill_short_pathname_representation_wrapper(char* out_rep,
|
void fill_short_pathname_representation_wrapper(char* out_rep,
|
||||||
const char *in_path, size_t size);
|
const char *in_path, size_t size);
|
||||||
|
|
||||||
/**
|
|
||||||
* path_basedir:
|
|
||||||
* @path : path
|
|
||||||
*
|
|
||||||
* Extracts base directory by mutating path.
|
|
||||||
* Keeps trailing '/'.
|
|
||||||
**/
|
|
||||||
void path_basedir_wrapper(char *path);
|
|
||||||
|
|
||||||
const char *file_path_str(enum file_path_enum enum_idx);
|
const char *file_path_str(enum file_path_enum enum_idx);
|
||||||
|
|
||||||
bool fill_pathname_application_data(char *s, size_t len);
|
bool fill_pathname_application_data(char *s, size_t len);
|
||||||
|
@ -30,6 +30,8 @@
|
|||||||
|
|
||||||
#include <boolean.h>
|
#include <boolean.h>
|
||||||
#include <file/file_path.h>
|
#include <file/file_path.h>
|
||||||
|
#include <retro_assert.h>
|
||||||
|
#include <string/stdstring.h>
|
||||||
|
|
||||||
#ifndef __MACH__
|
#ifndef __MACH__
|
||||||
#include <compat/strl.h>
|
#include <compat/strl.h>
|
||||||
@ -912,3 +914,239 @@ void fill_short_pathname_representation_noext(char* out_rep,
|
|||||||
fill_short_pathname_representation(out_rep, in_path, size);
|
fill_short_pathname_representation(out_rep, in_path, size);
|
||||||
path_remove_extension(out_rep);
|
path_remove_extension(out_rep);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void fill_pathname_expand_special(char *out_path,
|
||||||
|
const char *in_path, size_t size)
|
||||||
|
{
|
||||||
|
#if !defined(RARCH_CONSOLE)
|
||||||
|
if (*in_path == '~')
|
||||||
|
{
|
||||||
|
const char *home = getenv("HOME");
|
||||||
|
if (home)
|
||||||
|
{
|
||||||
|
size_t src_size = strlcpy(out_path, home, size);
|
||||||
|
retro_assert(src_size < size);
|
||||||
|
|
||||||
|
out_path += src_size;
|
||||||
|
size -= src_size;
|
||||||
|
in_path++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if ((in_path[0] == ':') &&
|
||||||
|
(
|
||||||
|
(in_path[1] == '/')
|
||||||
|
#ifdef _WIN32
|
||||||
|
|| (in_path[1] == '\\')
|
||||||
|
#endif
|
||||||
|
)
|
||||||
|
)
|
||||||
|
{
|
||||||
|
size_t src_size;
|
||||||
|
char *application_dir = (char*)malloc(PATH_MAX_LENGTH * sizeof(char));
|
||||||
|
|
||||||
|
application_dir[0] = '\0';
|
||||||
|
|
||||||
|
fill_pathname_application_path(application_dir,
|
||||||
|
PATH_MAX_LENGTH * sizeof(char));
|
||||||
|
path_basedir_wrapper(application_dir);
|
||||||
|
|
||||||
|
src_size = strlcpy(out_path, application_dir, size);
|
||||||
|
retro_assert(src_size < size);
|
||||||
|
|
||||||
|
free(application_dir);
|
||||||
|
|
||||||
|
out_path += src_size;
|
||||||
|
size -= src_size;
|
||||||
|
in_path += 2;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
retro_assert(strlcpy(out_path, in_path, size) < size);
|
||||||
|
}
|
||||||
|
|
||||||
|
void fill_pathname_abbreviate_special(char *out_path,
|
||||||
|
const char *in_path, size_t size)
|
||||||
|
{
|
||||||
|
#if !defined(RARCH_CONSOLE)
|
||||||
|
unsigned i;
|
||||||
|
const char *candidates[3];
|
||||||
|
const char *notations[3];
|
||||||
|
char *application_dir = (char*)malloc(PATH_MAX_LENGTH * sizeof(char));
|
||||||
|
const char *home = getenv("HOME");
|
||||||
|
|
||||||
|
application_dir[0] = '\0';
|
||||||
|
|
||||||
|
/* application_dir could be zero-string. Safeguard against this.
|
||||||
|
*
|
||||||
|
* Keep application dir in front of home, moving app dir to a
|
||||||
|
* new location inside home would break otherwise. */
|
||||||
|
|
||||||
|
/* ugly hack - use application_dir pointer
|
||||||
|
* before filling it in. C89 reasons */
|
||||||
|
candidates[0] = application_dir;
|
||||||
|
candidates[1] = home;
|
||||||
|
candidates[2] = NULL;
|
||||||
|
|
||||||
|
notations [0] = ":";
|
||||||
|
notations [1] = "~";
|
||||||
|
notations [2] = NULL;
|
||||||
|
|
||||||
|
fill_pathname_application_path(application_dir,
|
||||||
|
PATH_MAX_LENGTH * sizeof(char));
|
||||||
|
path_basedir_wrapper(application_dir);
|
||||||
|
|
||||||
|
for (i = 0; candidates[i]; i++)
|
||||||
|
{
|
||||||
|
if (!string_is_empty(candidates[i]) &&
|
||||||
|
strstr(in_path, candidates[i]) == in_path)
|
||||||
|
{
|
||||||
|
size_t src_size = strlcpy(out_path, notations[i], size);
|
||||||
|
|
||||||
|
retro_assert(src_size < size);
|
||||||
|
|
||||||
|
out_path += src_size;
|
||||||
|
size -= src_size;
|
||||||
|
in_path += strlen(candidates[i]);
|
||||||
|
|
||||||
|
if (!path_char_is_slash(*in_path))
|
||||||
|
{
|
||||||
|
retro_assert(strlcpy(out_path,
|
||||||
|
path_default_slash(), size) < size);
|
||||||
|
out_path++;
|
||||||
|
size--;
|
||||||
|
}
|
||||||
|
|
||||||
|
break; /* Don't allow more abbrevs to take place. */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
free(application_dir);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
retro_assert(strlcpy(out_path, in_path, size) < size);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* path_basedir:
|
||||||
|
* @path : path
|
||||||
|
*
|
||||||
|
* Extracts base directory by mutating path.
|
||||||
|
* Keeps trailing '/'.
|
||||||
|
**/
|
||||||
|
void path_basedir_wrapper(char *path)
|
||||||
|
{
|
||||||
|
char *last = NULL;
|
||||||
|
if (strlen(path) < 2)
|
||||||
|
return;
|
||||||
|
|
||||||
|
#ifdef HAVE_COMPRESSION
|
||||||
|
/* We want to find the directory with the archive in basedir. */
|
||||||
|
last = (char*)path_get_archive_delim(path);
|
||||||
|
if (last)
|
||||||
|
*last = '\0';
|
||||||
|
#endif
|
||||||
|
|
||||||
|
last = find_last_slash(path);
|
||||||
|
|
||||||
|
if (last)
|
||||||
|
last[1] = '\0';
|
||||||
|
else
|
||||||
|
snprintf(path, 3, ".%s", path_default_slash());
|
||||||
|
}
|
||||||
|
|
||||||
|
#if !defined(RARCH_CONSOLE)
|
||||||
|
void fill_pathname_application_path(char *s, size_t len)
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
#ifdef __APPLE__
|
||||||
|
CFBundleRef bundle = CFBundleGetMainBundle();
|
||||||
|
#endif
|
||||||
|
#ifdef _WIN32
|
||||||
|
DWORD ret;
|
||||||
|
wchar_t wstr[PATH_MAX_LENGTH] = {0};
|
||||||
|
#endif
|
||||||
|
#ifdef __HAIKU__
|
||||||
|
image_info info;
|
||||||
|
int32_t cookie = 0;
|
||||||
|
#endif
|
||||||
|
(void)i;
|
||||||
|
|
||||||
|
if (!len)
|
||||||
|
return;
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
#ifdef LEGACY_WIN32
|
||||||
|
ret = GetModuleFileNameA(GetModuleHandle(NULL), s, len);
|
||||||
|
#else
|
||||||
|
ret = GetModuleFileNameW(GetModuleHandle(NULL), wstr, ARRAY_SIZE(wstr));
|
||||||
|
|
||||||
|
if (*wstr)
|
||||||
|
{
|
||||||
|
char *str = utf16_to_utf8_string_alloc(wstr);
|
||||||
|
|
||||||
|
if (str)
|
||||||
|
{
|
||||||
|
strlcpy(s, str, len);
|
||||||
|
free(str);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
s[ret] = '\0';
|
||||||
|
#elif defined(__APPLE__)
|
||||||
|
if (bundle)
|
||||||
|
{
|
||||||
|
CFURLRef bundle_url = CFBundleCopyBundleURL(bundle);
|
||||||
|
CFStringRef bundle_path = CFURLCopyPath(bundle_url);
|
||||||
|
CFStringGetCString(bundle_path, s, len, kCFStringEncodingUTF8);
|
||||||
|
CFRelease(bundle_path);
|
||||||
|
CFRelease(bundle_url);
|
||||||
|
|
||||||
|
retro_assert(strlcat(s, "nobin", len) < len);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
#elif defined(__HAIKU__)
|
||||||
|
while (get_next_image_info(0, &cookie, &info) == B_OK)
|
||||||
|
{
|
||||||
|
if (info.type == B_APP_IMAGE)
|
||||||
|
{
|
||||||
|
strlcpy(s, info.name, len);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#elif defined(__QNX__)
|
||||||
|
char *buff = malloc(len);
|
||||||
|
|
||||||
|
if(_cmdname(buff))
|
||||||
|
strlcpy(s, buff, len);
|
||||||
|
|
||||||
|
free(buff);
|
||||||
|
#else
|
||||||
|
{
|
||||||
|
pid_t pid;
|
||||||
|
static const char *exts[] = { "exe", "file", "path/a.out" };
|
||||||
|
char link_path[255];
|
||||||
|
|
||||||
|
link_path[0] = *s = '\0';
|
||||||
|
pid = getpid();
|
||||||
|
|
||||||
|
/* Linux, BSD and Solaris paths. Not standardized. */
|
||||||
|
for (i = 0; i < ARRAY_SIZE(exts); i++)
|
||||||
|
{
|
||||||
|
ssize_t ret;
|
||||||
|
|
||||||
|
snprintf(link_path, sizeof(link_path), "/proc/%u/%s",
|
||||||
|
(unsigned)pid, exts[i]);
|
||||||
|
ret = readlink(link_path, s, len - 1);
|
||||||
|
|
||||||
|
if (ret >= 0)
|
||||||
|
{
|
||||||
|
s[ret] = '\0';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* RARCH_ERR("Cannot resolve application path! This should not happen.\n"); */
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
@ -389,6 +389,15 @@ void fill_pathname_expand_special(char *out_path,
|
|||||||
void fill_pathname_abbreviate_special(char *out_path,
|
void fill_pathname_abbreviate_special(char *out_path,
|
||||||
const char *in_path, size_t size);
|
const char *in_path, size_t size);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* path_basedir:
|
||||||
|
* @path : path
|
||||||
|
*
|
||||||
|
* Extracts base directory by mutating path.
|
||||||
|
* Keeps trailing '/'.
|
||||||
|
**/
|
||||||
|
void path_basedir_wrapper(char *path);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* path_char_is_slash:
|
* path_char_is_slash:
|
||||||
* @c : character
|
* @c : character
|
||||||
|
Loading…
x
Reference in New Issue
Block a user