1
0
mirror of https://github.com/libretro/RetroArch synced 2024-07-05 17:58:41 +00:00

win32: add Unicode versions of getenv, GetModuleFileName, LoadLibrary and _mkdir

This commit is contained in:
Brad Parker 2017-12-27 02:55:53 +00:00
parent fee7ab9dc8
commit a3a5f6e07e
3 changed files with 71 additions and 2 deletions

View File

@ -13,6 +13,14 @@
* If not, see <http://www.gnu.org/licenses/>.
*/
/* Assume W-functions do not work below Win2K and Xbox platforms */
#if defined(_WIN32_WINNT) && _WIN32_WINNT < 0x0500 || defined(_XBOX)
#ifndef LEGACY_WIN32
#define LEGACY_WIN32
#endif
#endif
#ifdef _WIN32
#include <direct.h>
@ -45,6 +53,7 @@
#include <compat/posix_string.h>
#include <retro_assert.h>
#include <retro_miscellaneous.h>
#include <encodings/utf.h>
#ifdef HAVE_CONFIG_H
#include "config.h"
@ -171,6 +180,7 @@ void fill_pathname_abbreviate_special(char *out_path,
bool fill_pathname_application_data(char *s, size_t len)
{
#if defined(_WIN32) && !defined(_XBOX)
#ifdef LEGACY_WIN32
const char *appdata = getenv("APPDATA");
if (appdata)
@ -178,6 +188,21 @@ bool fill_pathname_application_data(char *s, size_t len)
strlcpy(s, appdata, len);
return true;
}
#else
const wchar_t *appdataW = _wgetenv(L"APPDATA");
if (appdataW)
{
char *appdata = utf16_to_utf8_string_alloc(appdataW);
if (appdata)
{
strlcpy(s, appdata, len);
free(appdata);
return true;
}
}
#endif
#elif defined(OSX)
const char *appdata = getenv("HOME");
@ -224,7 +249,8 @@ void fill_pathname_application_path(char *s, size_t len)
#endif
#ifdef _WIN32
DWORD ret;
wchar_t ws[PATH_MAX_LENGTH] = {0};
char *str;
wchar_t wstr[PATH_MAX_LENGTH] = {0};
#endif
#ifdef __HAIKU__
image_info info;
@ -236,7 +262,22 @@ void fill_pathname_application_path(char *s, size_t len)
return;
#ifdef _WIN32
ret = GetModuleFileName(GetModuleHandle(NULL), s, len - 1);
#ifdef LEGACY_WIN32
ret = GetModuleFileNameA(GetModuleHandle(NULL), s, len);
#else
ret = GetModuleFileNameW(GetModuleHandle(NULL), wstr, ARRAY_SIZE(wstr));
if (*wstr)
{
str = utf16_to_utf8_string_alloc(wstr);
if (str)
{
strlcpy(s, str, len);
free(str);
}
}
#endif
s[ret] = '\0';
#elif defined(__APPLE__)
if (bundle)

View File

@ -23,6 +23,7 @@
#include <string.h>
#include <stdio.h>
#include <dynamic/dylib.h>
#include <encodings/utf.h>
#ifdef NEED_DYNAMIC
@ -33,6 +34,15 @@
#include <dlfcn.h>
#endif
/* Assume W-functions do not work below Win2K and Xbox platforms */
#if defined(_WIN32_WINNT) && _WIN32_WINNT < 0x0500 || defined(_XBOX)
#ifndef LEGACY_WIN32
#define LEGACY_WIN32
#endif
#endif
#ifdef _WIN32
static char last_dyn_error[512];
@ -65,7 +75,14 @@ dylib_t dylib_load(const char *path)
{
#ifdef _WIN32
int prevmode = SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX);
#ifdef LEGACY_WIN32
dylib_t lib = LoadLibrary(path);
#else
wchar_t *pathW = utf8_to_utf16_string_alloc(path);
dylib_t lib = LoadLibraryW(pathW);
free(pathW);
#endif
SetErrorMode(prevmode);

View File

@ -275,7 +275,18 @@ bool path_mkdir(const char *dir)
if (norecurse)
{
#if defined(_WIN32)
#ifdef LEGACY_WIN32
int ret = _mkdir(dir);
#else
wchar_t *dirW = utf8_to_utf16_string_alloc(dir);
int ret = -1;
if (dirW)
{
ret = _wmkdir(dirW);
free(dirW);
}
#endif
#elif defined(IOS)
int ret = mkdir(dir, 0755);
#elif defined(VITA) || defined(PSP)