Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Ensure that g_settings.libretro is absolute path.

Avoid issues when relative libretro paths are stored in ROM history.
  • Loading branch information...
commit df79b8ea3d463339769ca1cc685cd3facb582460 1 parent ef257a6
@Themaister authored
Showing with 32 additions and 0 deletions.
  1. +4 −0 dynamic.c
  2. +4 −0 file.h
  3. +24 −0 file_path.c
View
4 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)
View
4 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.
View
24 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))
Please sign in to comment.
Something went wrong with that request. Please try again.