2018-11-16 00:31:39 +01: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 23:53:39 +01:00
|
|
|
|
2010-09-25 19:35:19 +02: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 15:44:42 +02:00
|
|
|
CPToWide::CPToWide(const char *chars, unsigned int cp) {
|
|
|
|
int requiredChars = MultiByteToWideChar(cp,0,chars,-1,wideChars,0);
|
2012-07-22 14:57:35 +02:00
|
|
|
wideChars = new wchar_t[requiredChars];
|
2012-10-18 15:44:42 +02: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 14:57:35 +02:00
|
|
|
}
|
|
|
|
|
2013-01-31 14:04:30 +01:00
|
|
|
#ifdef UNICODE
|
|
|
|
|
2010-09-25 19:35:19 +02: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 03:11:42 +02:00
|
|
|
extern "C" int _twopen(const char *filename, int oflag, int pmode) {
|
|
|
|
return _wopen(Utf8ToWide(filename), oflag, pmode);
|
|
|
|
}
|
|
|
|
|
2018-05-24 18:19:00 +02:00
|
|
|
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);
|
2018-05-24 18:22:20 +02:00
|
|
|
free(resolved);
|
2018-05-24 18:19:00 +02:00
|
|
|
dst[len - 1] = '\0';
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-03-20 23:53:39 +01:00
|
|
|
#endif // UNICODE
|