Ensure that g_settings.libretro is absolute path.

Avoid issues when relative libretro paths are stored in ROM history.
This commit is contained in:
Themaister 2013-05-13 23:25:37 +02:00
parent ef257a6e8e
commit df79b8ea3d
3 changed files with 32 additions and 0 deletions

View File

@ -290,6 +290,10 @@ static void load_symbols(bool is_dummy)
strlcpy(g_settings.libretro, libretro_core_buffer, sizeof(g_settings.libretro));
}
// Need to use absolute path for this setting. It can be saved to ROM history,
// and a relative path would break in that scenario.
path_resolve_realpath(g_settings.libretro, sizeof(g_settings.libretro));
RARCH_LOG("Loading dynamic libretro from: \"%s\"\n", g_settings.libretro);
lib_handle = dylib_load(g_settings.libretro);
if (!lib_handle)

4
file.h
View File

@ -84,6 +84,10 @@ void path_basedir(char *path);
// Assumes that path is a directory. Keeps trailing '/'.
void path_parent_dir(char *path);
// Turns relative paths into absolute path.
// If relative, rebases on current working dir.
void path_resolve_realpath(char *buf, size_t size);
bool path_is_absolute(const char *path);
// Path-name operations.

View File

@ -532,6 +532,30 @@ bool path_is_absolute(const char *path)
#endif
}
void path_resolve_realpath(char *buf, size_t size)
{
#ifndef RARCH_CONSOLE
char tmp[PATH_MAX];
strlcpy(tmp, buf, sizeof(tmp));
#ifdef _WIN32
if (!_fullpath(buf, tmp, size))
strlcpy(buf, tmp, size);
#else
rarch_assert(size >= PATH_MAX);
// NOTE: realpath() expects at least PATH_MAX bytes in buf.
// Technically, PATH_MAX needn't be defined, but we rely on it anyways.
// POSIX 2008 can automatically allocate for you, but don't rely on that.
if (!realpath(tmp, buf))
strlcpy(buf, tmp, size);
#endif
#else
(void)buf;
(void)size;
#endif
}
void fill_pathname_resolve_relative(char *out_path, const char *in_refpath, const char *in_path, size_t size)
{
if (path_is_absolute(in_path))