From 22e2a33167b73975b8ac2161cda6924975e7bee5 Mon Sep 17 00:00:00 2001 From: Adrian Johnson Date: Sun, 3 Dec 2017 20:27:08 +1030 Subject: [PATCH 10/13] gfile: replace open coded utf8 to utf16 conversion with utf8ToUtf16() also removes Win95/Win98 code. Modern compilers no longer support Win95/Win98 targets. --- goo/gfile.cc | 62 ++++++------------------------------------------------------ 1 file changed, 6 insertions(+), 56 deletions(-) diff --git a/goo/gfile.cc b/goo/gfile.cc index 3e5892c8..bc7fdb52 100644 --- a/goo/gfile.cc +++ b/goo/gfile.cc @@ -465,62 +465,12 @@ GooString *fileNameToUTF8(wchar_t *path) { FILE *openFile(const char *path, const char *mode) { #ifdef _WIN32 - OSVERSIONINFO version; - wchar_t wPath[_MAX_PATH + 1]; - char nPath[_MAX_PATH + 1]; - wchar_t wMode[8]; - const char *p; - size_t i; - - // NB: _wfopen is only available in NT - version.dwOSVersionInfoSize = sizeof(version); - GetVersionEx(&version); - if (version.dwPlatformId == VER_PLATFORM_WIN32_NT) { - for (p = path, i = 0; *p && i < _MAX_PATH; ++i) { - if ((p[0] & 0xe0) == 0xc0 && - p[1] && (p[1] & 0xc0) == 0x80) { - wPath[i] = (wchar_t)(((p[0] & 0x1f) << 6) | - (p[1] & 0x3f)); - p += 2; - } else if ((p[0] & 0xf0) == 0xe0 && - p[1] && (p[1] & 0xc0) == 0x80 && - p[2] && (p[2] & 0xc0) == 0x80) { - wPath[i] = (wchar_t)(((p[0] & 0x0f) << 12) | - ((p[1] & 0x3f) << 6) | - (p[2] & 0x3f)); - p += 3; - } else { - wPath[i] = (wchar_t)(p[0] & 0xff); - p += 1; - } - } - wPath[i] = (wchar_t)0; - for (i = 0; (i < sizeof(mode) - 1) && mode[i]; ++i) { - wMode[i] = (wchar_t)(mode[i] & 0xff); - } - wMode[i] = (wchar_t)0; - return _wfopen(wPath, wMode); - } else { - for (p = path, i = 0; *p && i < _MAX_PATH; ++i) { - if ((p[0] & 0xe0) == 0xc0 && - p[1] && (p[1] & 0xc0) == 0x80) { - nPath[i] = (char)(((p[0] & 0x1f) << 6) | - (p[1] & 0x3f)); - p += 2; - } else if ((p[0] & 0xf0) == 0xe0 && - p[1] && (p[1] & 0xc0) == 0x80 && - p[2] && (p[2] & 0xc0) == 0x80) { - nPath[i] = (char)(((p[1] & 0x3f) << 6) | - (p[2] & 0x3f)); - p += 3; - } else { - nPath[i] = p[0]; - p += 1; - } - } - nPath[i] = '\0'; - return fopen(nPath, mode); - } + wchar_t *wPath = (wchar_t *)utf8ToUtf16(path); + wchar_t *wMode = (wchar_t *)utf8ToUtf16(mode); + FILE *file = _wfopen(wPath, wMode); + delete wPath; + delete wMode; + return file; #else return fopen(path, mode); #endif -- 2.11.0