root/lang/c/libintl-msvc/recipes/loadmsgcat-windows.h @ 25160

Revision 25160, 1.2 kB (checked in by saturday06, 6 years ago)

hsn

  • 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
14/* http://msdn.microsoft.com/en-us/library/aa365247(VS.85).aspx */
15#define WCHAR_LIBINTL_MAX_PATH 33000
16
17int
18open_windows_utf8 (const char *pathname8, int flags)
19{
20  wchar_t *pathname16 = NULL;
21  unsigned int num_elements = 0;
22  int result = 0;
23
24  num_elements = MultiByteToWideChar (CP_UTF8, 0, pathname8, -1, NULL, 0);
25  if (num_elements == 0)
26    {
27      errno = EACCES;
28      return -1;
29    }
30
31  if (num_elements >= WCHAR_LIBINTL_MAX_PATH)
32    {
33      errno = EACCES;
34      return -1;
35    }
36
37  pathname16 = (wchar_t *)malloc (num_elements * sizeof(wchar_t));
38  if (0 == MultiByteToWideChar (CP_UTF8, 0, pathname8, -1,
39                                pathname16, num_elements))
40    {
41      free (pathname16);
42      errno = EACCES;
43      return -1;
44    }
45
46  result = _wopen (pathname16, flags);
47  free (pathname16);
48  return result;
49}
50
51#undef open
52#define open(name, flags) open_windows_utf8(name, flags)
53
54#endif // (defined(_MSC_VER) || defined(__MINGW32_VERSION)) && (defined(UNICODE) || defined(_UNICODE))
55#endif
56
Note: See TracBrowser for help on using the browser.