From a87e34906cd9f7956d62f2212dd557df3b134296 Mon Sep 17 00:00:00 2001 From: Yamagi Burmeister Date: Mon, 5 Feb 2018 09:13:45 +0100 Subject: [PATCH] Implement Q_fopen() for Windows. This is done in shared.c so that's available for both the client / server / renderer and the game. A work around for older game DLL will be added at a later time. --- src/common/header/shared.h | 2 +- src/common/shared/shared.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/common/header/shared.h b/src/common/header/shared.h index 8fa6b232..a6735d33 100644 --- a/src/common/header/shared.h +++ b/src/common/header/shared.h @@ -257,7 +257,7 @@ int Q_strlcat(char *dst, const char *src, int size); /* Unicode wrappers around fopen(). */ #ifdef _WIN32 -#error "Not implemented yet" +FILE *Q_fopen(const char *file, const char *mode); #else #define Q_fopen(file, mode) fopen(file, mode) #endif diff --git a/src/common/shared/shared.c b/src/common/shared/shared.c index f9f84794..17ba627b 100644 --- a/src/common/shared/shared.c +++ b/src/common/shared/shared.c @@ -1144,6 +1144,35 @@ Q_strlcat(char *dst, const char *src, int size) return (d - dst) + Q_strlcpy(d, src, size); } +/* + * An unicode compatible fopen() Wrapper for Windows. + */ +#ifdef _WIN32 +#include + +FILE *Q_fopen(const char *file, const char *mode) +{ + WCHAR wfile[MAX_OSPATH]; + WCHAR wmode[16]; + + int len = MultiByteToWideChar(CP_UTF8, 0, file, -1, wfile, MAX_OSPATH); + + if (len > 0) + { + if (MultiByteToWideChar(CP_UTF8, 0, mode, -1, wmode, 16) > 0) + { + FILE *ret; + if(_wfopen_s(&ret, wfile, wmode) == 0) + { + return ret; + } + } + } + + return NULL; +} +#endif + /* * ===================================================================== *