From ba76c1c2be22b58c856c567f610ce7a55a85f5f2 Mon Sep 17 00:00:00 2001 From: OV2 Date: Thu, 24 May 2018 18:19:00 +0200 Subject: [PATCH] win32: handle unicode when loading glsl shaders --- shaders/shader_platform.h | 7 +++++-- win32/_tfwopen.cpp | 7 +++++++ win32/_tfwopen.h | 1 + 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/shaders/shader_platform.h b/shaders/shader_platform.h index 2c2f004d..e9a1b180 100644 --- a/shaders/shader_platform.h +++ b/shaders/shader_platform.h @@ -14,10 +14,13 @@ #include "gl_core_3_1.h" #include +#ifdef UNICODE +#define chdir(dir) _wchdir(Utf8ToWide(dir)) +#define realpath(src, resolved) _twfullpath(resolved, src, PATH_MAX) +#else #define chdir(dir) _chdir(dir) #define realpath(src, resolved) _fullpath(resolved, src, PATH_MAX) - - +#endif #endif diff --git a/win32/_tfwopen.cpp b/win32/_tfwopen.cpp index 345cf7be..dbd703ac 100644 --- a/win32/_tfwopen.cpp +++ b/win32/_tfwopen.cpp @@ -229,4 +229,11 @@ extern "C" int _twopen(const char *filename, int oflag, int pmode) { return _wopen(Utf8ToWide(filename), oflag, pmode); } +extern "C" void _twfullpath(char* dst, const char* src, int len) { + wchar_t *resolved = _wfullpath(NULL, Utf8ToWide(src), MAX_PATH); + strncpy(dst, WideToUtf8(resolved), len); + dst[len - 1] = '\0'; + return; +} + #endif // UNICODE diff --git a/win32/_tfwopen.h b/win32/_tfwopen.h index f7d5763b..c8a5cb90 100644 --- a/win32/_tfwopen.h +++ b/win32/_tfwopen.h @@ -198,6 +198,7 @@ extern "C" { FILE *_tfwopen(const char *filename, const char *mode ); int _twremove(const char *filename ); int _twopen(const char *filename, int oflag, int pmode); +void _twfullpath(char* dst, const char* src, int len); #ifdef __cplusplus }