]>
Commit | Line | Data |
---|---|---|
1e59de90 TL |
1 | diff --git "a/gettext-runtime/intl/loadmsgcat.c" "b/gettext-runtime/intl/loadmsgcat.c" |
2 | index 63351523..c078de3f 100644 | |
3 | --- a/gettext-runtime/intl/loadmsgcat.c | |
4 | +++ b/gettext-runtime/intl/loadmsgcat.c | |
5 | @@ -388,6 +388,55 @@ char *alloca (); | |
6 | # define munmap(addr, len) __munmap (addr, len) | |
7 | #endif | |
8 | ||
9 | +#ifdef _WIN32 | |
10 | +/* Provide wrapper of "open" for Windows that supports UTF-8 filenames. */ | |
11 | +# ifndef WIN32_LEAN_AND_MEAN | |
12 | +# define WIN32_LEAN_AND_MEAN | |
13 | +# endif | |
14 | +# ifndef WIN32_EXTRA_LEAN | |
15 | +# define WIN32_EXTRA_LEAN | |
16 | +# endif | |
17 | +# undef NOMINMAX | |
18 | +# define NOMINMAX | |
19 | +# include <windows.h> // For: MultiByteToWideChar | |
20 | +# include <io.h> | |
21 | +# include <wchar.h> | |
22 | + | |
23 | +int _open_utf8_windows_wrapper( | |
24 | + const char *filename, | |
25 | + int flags | |
26 | +) | |
27 | +{ | |
28 | + int wstr_len = -1; | |
29 | + wchar_t* pUtf16FileName = NULL; | |
30 | + int fh = -1; | |
31 | + | |
32 | + // on Windows, convert the filename from UTF-8 to UTF-16 | |
33 | + wstr_len = MultiByteToWideChar(CP_UTF8, 0, filename, -1, NULL, 0); | |
34 | + if (wstr_len <= 0) | |
35 | + { | |
36 | + // MultiByteToWideChar failed | |
37 | + errno = ENOENT; | |
38 | + return -1; | |
39 | + } | |
40 | + pUtf16FileName = malloc(wstr_len * sizeof(wchar_t)); | |
41 | + if (MultiByteToWideChar(CP_UTF8, 0, filename, -1, pUtf16FileName, wstr_len) == 0) | |
42 | + { | |
43 | + // MultiByteToWideChar failed | |
44 | + free(pUtf16FileName); | |
45 | + errno = ENOENT; | |
46 | + return -1; | |
47 | + } | |
48 | + | |
49 | + // and call _wopen | |
50 | + fh = _wopen(pUtf16FileName, flags); | |
51 | + | |
52 | + free(pUtf16FileName); | |
53 | + return fh; | |
54 | +} | |
55 | +# define open(name, flags) _open_utf8_windows_wrapper(name, flags) | |
56 | +#endif // #ifdef _WIN32 | |
57 | + | |
58 | /* For those losing systems which don't have `alloca' we have to add | |
59 | some additional code emulating it. */ | |
60 | #ifdef HAVE_ALLOCA |