|
Revision 25300, 1.2 kB
(checked in by saturday06, 4 years ago)
|
|
comit!
|
-
Property svn:executable set to
*
|
| Line | |
|---|
| 1 | /* |
|---|
| 2 | |
|---|
| 3 | #include "loadmsgcat-windows.h" |
|---|
| 4 | |
|---|
| 5 | */ |
|---|
| 6 | |
|---|
| 7 | #ifndef LOADMSGCAT_WINDOWS_H |
|---|
| 8 | #define LOADMSGCAT_WINDOWS_H 1 |
|---|
| 9 | |
|---|
| 10 | #if (defined(_MSC_VER) || defined(__MINGW32_VERSION)) && (defined(UNICODE) || defined(_UNICODE)) |
|---|
| 11 | |
|---|
| 12 | #include <windows.h> |
|---|
| 13 | #include <io.h> |
|---|
| 14 | |
|---|
| 15 | /* http://msdn.microsoft.com/en-us/library/aa365247(VS.85).aspx */ |
|---|
| 16 | #define WCHAR_LIBINTL_MAX_PATH 33000 |
|---|
| 17 | |
|---|
| 18 | int |
|---|
| 19 | open_windows_utf8 (const char *pathname8, int flags) |
|---|
| 20 | { |
|---|
| 21 | wchar_t *pathname16 = NULL; |
|---|
| 22 | unsigned int num_elements = 0; |
|---|
| 23 | int result = 0; |
|---|
| 24 | |
|---|
| 25 | num_elements = MultiByteToWideChar (CP_UTF8, 0, pathname8, -1, NULL, 0); |
|---|
| 26 | if (num_elements == 0) |
|---|
| 27 | { |
|---|
| 28 | errno = EACCES; |
|---|
| 29 | return -1; |
|---|
| 30 | } |
|---|
| 31 | |
|---|
| 32 | if (num_elements >= WCHAR_LIBINTL_MAX_PATH) |
|---|
| 33 | { |
|---|
| 34 | errno = EACCES; |
|---|
| 35 | return -1; |
|---|
| 36 | } |
|---|
| 37 | |
|---|
| 38 | pathname16 = (wchar_t *)malloc (num_elements * sizeof(wchar_t)); |
|---|
| 39 | if (0 == MultiByteToWideChar (CP_UTF8, 0, pathname8, -1, |
|---|
| 40 | pathname16, num_elements)) |
|---|
| 41 | { |
|---|
| 42 | free (pathname16); |
|---|
| 43 | errno = EACCES; |
|---|
| 44 | return -1; |
|---|
| 45 | } |
|---|
| 46 | |
|---|
| 47 | result = _wopen (pathname16, flags); |
|---|
| 48 | free (pathname16); |
|---|
| 49 | return result; |
|---|
| 50 | } |
|---|
| 51 | |
|---|
| 52 | #undef open |
|---|
| 53 | #define open(name, flags) open_windows_utf8(name, flags) |
|---|
| 54 | |
|---|
| 55 | #endif // (defined(_MSC_VER) || defined(__MINGW32_VERSION)) && (defined(UNICODE) || defined(_UNICODE)) |
|---|
| 56 | #endif |
|---|
| 57 | |
|---|