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.
This commit is contained in:
Yamagi Burmeister 2018-02-05 09:13:45 +01:00
parent 37ea3e1d58
commit a87e34906c
2 changed files with 30 additions and 1 deletions

View File

@ -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

View File

@ -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 <windows.h>
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
/*
* =====================================================================
*