Merge branch 'unicode-file-support' of https://github.com/jrsmith17/stb into temp

This commit is contained in:
Sean Barrett
2019-02-07 05:07:14 -08:00
2 changed files with 60 additions and 0 deletions

View File

@ -1143,12 +1143,40 @@ static void stbi__float_postprocess(float *result, int *x, int *y, int *comp, in
#ifndef STBI_NO_STDIO
char* stbi_convert_wchar_to_utf8(wchar_t* input) {
#ifdef _WINDOWS_
int outputSizeNeeded = WideCharToMultiByte(CP_UTF8, 0, &input[0], wcslen(input), NULL, 0, NULL, NULL);
char* temp = (char*)STBI_MALLOC(outputSizeNeeded);
int error = WideCharToMultiByte(65001, 0, input, -1, temp, outputSizeNeeded, NULL, NULL);
temp[outputSizeNeeded] = '\0';
return temp;
#else
return NULL;
#endif
}
static FILE *stbi__fopen(char const *filename, char const *mode)
{
FILE *f;
#if defined(_MSC_VER) && _MSC_VER >= 1400
#ifdef UNICODE
int filenameLength = MultiByteToWideChar(CP_UTF8, 0, filename, -1, NULL, 0);
wchar_t* wFilename = (wchar_t*)stbi__malloc(filenameLength * sizeof(wchar_t));
MultiByteToWideChar(CP_UTF8, 0, filename, -1, wFilename, filenameLength);
int modeLength = MultiByteToWideChar(CP_UTF8, 0, mode, -1, NULL, 0);
wchar_t* wMode = (wchar_t*)stbi__malloc(modeLength * sizeof(wchar_t));
MultiByteToWideChar(CP_UTF8, 0, mode, -1, wMode, modeLength);
if (0 != _wfopen_s(&f, wFilename, wMode))
f = 0;
STBI_FREE(wFilename);
STBI_FREE(wMode);
#else
if (0 != fopen_s(&f, filename, mode))
f=0;
#endif
#else
f = fopen(filename, mode);
#endif