2018-11-15 23:31:39 +00:00
|
|
|
/*****************************************************************************\
|
|
|
|
Snes9x - Portable Super Nintendo Entertainment System (TM) emulator.
|
|
|
|
This file is licensed under the Snes9x License.
|
|
|
|
For further information, consult the LICENSE file in the root directory.
|
|
|
|
\*****************************************************************************/
|
2011-03-20 22:53:39 +00:00
|
|
|
|
2010-09-25 17:35:19 +00:00
|
|
|
#include <windows.h>
|
|
|
|
#include "_tfwopen.h"
|
|
|
|
|
|
|
|
Utf8ToWide::Utf8ToWide(const char *utf8Chars) {
|
|
|
|
int requiredChars = MultiByteToWideChar(CP_UTF8,0,utf8Chars,-1,wideChars,0);
|
|
|
|
wideChars = new wchar_t[requiredChars];
|
|
|
|
MultiByteToWideChar(CP_UTF8,0,utf8Chars,-1,wideChars,requiredChars);
|
|
|
|
}
|
|
|
|
|
|
|
|
WideToUtf8::WideToUtf8(const wchar_t *wideChars) {
|
|
|
|
int requiredChars = WideCharToMultiByte(CP_UTF8,0,wideChars,-1,utf8Chars,0,NULL,NULL);
|
|
|
|
utf8Chars = new char[requiredChars];
|
|
|
|
WideCharToMultiByte(CP_UTF8,0,wideChars,-1,utf8Chars,requiredChars,NULL,NULL);
|
|
|
|
}
|
|
|
|
|
2012-10-18 13:44:42 +00:00
|
|
|
CPToWide::CPToWide(const char *chars, unsigned int cp) {
|
|
|
|
int requiredChars = MultiByteToWideChar(cp,0,chars,-1,wideChars,0);
|
2012-07-22 12:57:35 +00:00
|
|
|
wideChars = new wchar_t[requiredChars];
|
2012-10-18 13:44:42 +00:00
|
|
|
MultiByteToWideChar(cp,0,chars,-1,wideChars,requiredChars);
|
|
|
|
}
|
|
|
|
|
|
|
|
WideToCP::WideToCP(const wchar_t *wideChars, unsigned int cp) {
|
|
|
|
int requiredChars = WideCharToMultiByte(cp,0,wideChars,-1,cpchars,0,NULL,NULL);
|
|
|
|
cpchars = new char[requiredChars];
|
|
|
|
WideCharToMultiByte(cp,0,wideChars,-1,cpchars,requiredChars,NULL,NULL);
|
2012-07-22 12:57:35 +00:00
|
|
|
}
|
|
|
|
|
2013-01-31 13:04:30 +00:00
|
|
|
#ifdef UNICODE
|
|
|
|
|
2010-09-25 17:35:19 +00:00
|
|
|
extern "C" FILE *_tfwopen(const char *filename, const char *mode ) {
|
|
|
|
wchar_t mode_w[30];
|
|
|
|
lstrcpyn(mode_w,Utf8ToWide(mode),29);
|
|
|
|
mode_w[29]=L'\0';
|
|
|
|
return _wfopen(Utf8ToWide(filename),mode_w);
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" int _twremove(const char *filename ) {
|
|
|
|
return _wremove(Utf8ToWide(filename));
|
|
|
|
}
|
|
|
|
|
2011-05-07 01:11:42 +00:00
|
|
|
extern "C" int _twopen(const char *filename, int oflag, int pmode) {
|
|
|
|
return _wopen(Utf8ToWide(filename), oflag, pmode);
|
|
|
|
}
|
|
|
|
|
2019-01-15 22:23:39 +00:00
|
|
|
extern "C" char *_twfullpath(char* dst, const char* src, int len) {
|
2018-05-24 16:19:00 +00:00
|
|
|
wchar_t *resolved = _wfullpath(NULL, Utf8ToWide(src), MAX_PATH);
|
2019-01-15 22:23:39 +00:00
|
|
|
WideToUtf8 utf8resolved = WideToUtf8(resolved);
|
|
|
|
free(resolved);
|
|
|
|
if (dst == NULL)
|
|
|
|
{
|
|
|
|
len = strlen(utf8resolved) + 1;
|
|
|
|
dst = (char *)malloc(len);
|
|
|
|
}
|
|
|
|
strncpy(dst, utf8resolved, len);
|
2018-05-24 16:19:00 +00:00
|
|
|
dst[len - 1] = '\0';
|
2019-01-15 22:23:39 +00:00
|
|
|
return dst;
|
2018-05-24 16:19:00 +00:00
|
|
|
}
|
|
|
|
|
2011-03-20 22:53:39 +00:00
|
|
|
#endif // UNICODE
|