1 /***************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * Copyright (C) 1998 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al.
10 * This software is licensed as described in the file COPYING, which
11 * you should have received as part of this distribution. The terms
12 * are also available at https://curl.haxx.se/docs/copyright.html.
14 * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15 * copies of the Software, and permit persons to whom the Software is
16 * furnished to do so, under the terms of the COPYING file.
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
21 ***************************************************************************/
24 * This file is 'mem-include-scan' clean. See test 1132.
27 #include "curl_setup.h"
31 #include "curl_multibyte.h"
34 * MultiByte conversions using Windows kernel32 library.
37 wchar_t *curlx_convert_UTF8_to_wchar(const char *str_utf8)
39 wchar_t *str_w = NULL;
42 int str_w_len = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS,
43 str_utf8, -1, NULL, 0);
45 str_w = malloc(str_w_len * sizeof(wchar_t));
47 if(MultiByteToWideChar(CP_UTF8, 0, str_utf8, -1, str_w,
59 char *curlx_convert_wchar_to_UTF8(const wchar_t *str_w)
61 char *str_utf8 = NULL;
64 int bytes = WideCharToMultiByte(CP_UTF8, 0, str_w, -1,
67 str_utf8 = malloc(bytes);
69 if(WideCharToMultiByte(CP_UTF8, 0, str_w, -1, str_utf8, bytes,
83 #if defined(USE_WIN32_LARGE_FILES) || defined(USE_WIN32_SMALL_FILES)
85 FILE *curlx_win32_fopen(const char *filename, const char *mode)
89 wchar_t *filename_w = curlx_convert_UTF8_to_wchar(filename);
90 wchar_t *mode_w = curlx_convert_UTF8_to_wchar(mode);
91 if(filename_w && mode_w)
92 result = _wfopen(filename_w, mode_w);
99 return (fopen)(filename, mode);
102 int curlx_win32_stat(const char *path, struct_stat *buffer)
106 wchar_t *path_w = curlx_convert_UTF8_to_wchar(path);
107 #endif /* _UNICODE */
109 #if defined(USE_WIN32_SMALL_FILES)
110 #if defined(_UNICODE)
112 result = _wstat(path_w, buffer);
114 #endif /* _UNICODE */
115 result = _stat(path, buffer);
116 #else /* USE_WIN32_SMALL_FILES */
117 #if defined(_UNICODE)
119 result = _wstati64(path_w, buffer);
121 #endif /* _UNICODE */
122 result = _stati64(path, buffer);
123 #endif /* USE_WIN32_SMALL_FILES */
132 int curlx_win32_access(const char *path, int mode)
136 wchar_t *path_w = curlx_convert_UTF8_to_wchar(path);
137 #endif /* _UNICODE */
139 #if defined(_UNICODE)
141 result = _waccess(path_w, mode);
143 #endif /* _UNICODE */
144 result = _access(path, mode);
153 #endif /* USE_WIN32_LARGE_FILES || USE_WIN32_SMALL_FILES */