From df79b8ea3d463339769ca1cc685cd3facb582460 Mon Sep 17 00:00:00 2001 From: Themaister Date: Mon, 13 May 2013 23:25:37 +0200 Subject: [PATCH] Ensure that g_settings.libretro is absolute path. Avoid issues when relative libretro paths are stored in ROM history. --- dynamic.c | 4 ++++ file.h | 4 ++++ file_path.c | 24 ++++++++++++++++++++++++ 3 files changed, 32 insertions(+) diff --git a/dynamic.c b/dynamic.c index ef4df5843b..330dc51e08 100644 --- a/dynamic.c +++ b/dynamic.c @@ -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) diff --git a/file.h b/file.h index d2bf04c7d5..78e6e7b2fa 100644 --- a/file.h +++ b/file.h @@ -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. diff --git a/file_path.c b/file_path.c index ccaf1a95b4..be0aa82ec2 100644 --- a/file_path.c +++ b/file_path.c @@ -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))