Merge pull request #12459 from toshixm/fix_12103

Fix garbled path string
This commit is contained in:
Autechre 2021-07-08 12:05:07 +02:00 committed by GitHub
commit 375eb4b852
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -650,16 +650,31 @@ bool path_is_absolute(const char *path)
char *path_resolve_realpath(char *buf, size_t size, bool resolve_symlinks) char *path_resolve_realpath(char *buf, size_t size, bool resolve_symlinks)
{ {
#if !defined(RARCH_CONSOLE) && defined(RARCH_INTERNAL) #if !defined(RARCH_CONSOLE) && defined(RARCH_INTERNAL)
char tmp[PATH_MAX_LENGTH];
#ifdef _WIN32 #ifdef _WIN32
strlcpy(tmp, buf, sizeof(tmp)); char *ret = NULL;
if (!_fullpath(buf, tmp, size)) wchar_t abs_path[PATH_MAX_LENGTH];
wchar_t *rel_path = utf8_to_utf16_string_alloc(buf);
if (rel_path)
{ {
strlcpy(buf, tmp, size); if (_wfullpath(abs_path, rel_path, PATH_MAX_LENGTH))
return NULL; {
char *tmp = utf16_to_utf8_string_alloc(abs_path);
if (tmp)
{
strlcpy(buf, tmp, size);
free(tmp);
ret = buf;
}
}
free(rel_path);
} }
return buf;
return ret;
#else #else
char tmp[PATH_MAX_LENGTH];
size_t t; size_t t;
char *p; char *p;
const char *next; const char *next;