function newfopen to replace fopen

by reading wide char strings
This commit is contained in:
h_vogt 2017-10-04 14:20:51 +02:00 committed by Holger Vogt
parent 904cc4a1bc
commit e46aab1788
1 changed files with 22 additions and 0 deletions

View File

@ -257,3 +257,25 @@ ngdirname(const char *name)
}
#endif
#ifndef EXT_ASC
#if defined(__MINGW__) || defined(_MSC_VER)
#undef BOOLEAN
#include <windows.h>
FILE *
newfopen(char *fn, char* md)
{
wchar_t wfn[BSIZE_SP];
wchar_t wmd[16];
MultiByteToWideChar(CP_UTF8, 0, md, -1, wmd, 15);
MultiByteToWideChar(CP_UTF8, 0, fn, -1, wfn, BSIZE_SP - 1);
if (MultiByteToWideChar(CP_UTF8, 0, fn, -1, wfn, BSIZE_SP - 1) == 0) {
fprintf(stderr, "UTF-8 to UTF-16 conversion failed with 0x%x\n", GetLastError());
fprintf(stderr, "%s could not be converted\n", fn);
return NULL;
}
return _wfopen(wfn, wmd);
}
#endif
#endif