1 /***************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * Copyright (C) 1998 - 2022, 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.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 * SPDX-License-Identifier: curl
23 ***************************************************************************/
26 * This file is 'mem-include-scan' clean, which means memdebug.h and
27 * curl_memory.h are purposely not included in this file. See test 1132.
29 * The functions in this file are curlx functions which are not tracked by the
30 * curl memory tracker memdebug.
33 #include "curl_setup.h"
37 #include "curl_multibyte.h"
40 * MultiByte conversions using Windows kernel32 library.
43 wchar_t *curlx_convert_UTF8_to_wchar(const char *str_utf8)
45 wchar_t *str_w = NULL;
48 int str_w_len = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS,
49 str_utf8, -1, NULL, 0);
51 str_w = malloc(str_w_len * sizeof(wchar_t));
53 if(MultiByteToWideChar(CP_UTF8, 0, str_utf8, -1, str_w,
65 char *curlx_convert_wchar_to_UTF8(const wchar_t *str_w)
67 char *str_utf8 = NULL;
70 int bytes = WideCharToMultiByte(CP_UTF8, 0, str_w, -1,
73 str_utf8 = malloc(bytes);
75 if(WideCharToMultiByte(CP_UTF8, 0, str_w, -1, str_utf8, bytes,
89 #if defined(USE_WIN32_LARGE_FILES) || defined(USE_WIN32_SMALL_FILES)
91 int curlx_win32_open(const char *filename, int oflag, ...)
97 wchar_t *filename_w = curlx_convert_UTF8_to_wchar(filename);
101 va_start(param, oflag);
103 pmode = va_arg(param, int);
108 result = _wopen(filename_w, oflag, pmode);
109 curlx_unicodefree(filename_w);
115 return (_open)(filename, oflag, pmode);
119 FILE *curlx_win32_fopen(const char *filename, const char *mode)
123 wchar_t *filename_w = curlx_convert_UTF8_to_wchar(filename);
124 wchar_t *mode_w = curlx_convert_UTF8_to_wchar(mode);
125 if(filename_w && mode_w)
126 result = _wfopen(filename_w, mode_w);
129 curlx_unicodefree(filename_w);
130 curlx_unicodefree(mode_w);
133 return (fopen)(filename, mode);
137 int curlx_win32_stat(const char *path, struct_stat *buffer)
141 wchar_t *path_w = curlx_convert_UTF8_to_wchar(path);
143 #if defined(USE_WIN32_SMALL_FILES)
144 result = _wstat(path_w, buffer);
146 result = _wstati64(path_w, buffer);
148 curlx_unicodefree(path_w);
154 #if defined(USE_WIN32_SMALL_FILES)
155 return _stat(path, buffer);
157 return _stati64(path, buffer);
162 int curlx_win32_access(const char *path, int mode)
164 #if defined(_UNICODE)
166 wchar_t *path_w = curlx_convert_UTF8_to_wchar(path);
168 result = _waccess(path_w, mode);
169 curlx_unicodefree(path_w);
175 return _access(path, mode);
179 #endif /* USE_WIN32_LARGE_FILES || USE_WIN32_SMALL_FILES */