113498266Sopenharmony_ci#ifndef HEADER_CURL_MULTIBYTE_H 213498266Sopenharmony_ci#define HEADER_CURL_MULTIBYTE_H 313498266Sopenharmony_ci/*************************************************************************** 413498266Sopenharmony_ci * _ _ ____ _ 513498266Sopenharmony_ci * Project ___| | | | _ \| | 613498266Sopenharmony_ci * / __| | | | |_) | | 713498266Sopenharmony_ci * | (__| |_| | _ <| |___ 813498266Sopenharmony_ci * \___|\___/|_| \_\_____| 913498266Sopenharmony_ci * 1013498266Sopenharmony_ci * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al. 1113498266Sopenharmony_ci * 1213498266Sopenharmony_ci * This software is licensed as described in the file COPYING, which 1313498266Sopenharmony_ci * you should have received as part of this distribution. The terms 1413498266Sopenharmony_ci * are also available at https://curl.se/docs/copyright.html. 1513498266Sopenharmony_ci * 1613498266Sopenharmony_ci * You may opt to use, copy, modify, merge, publish, distribute and/or sell 1713498266Sopenharmony_ci * copies of the Software, and permit persons to whom the Software is 1813498266Sopenharmony_ci * furnished to do so, under the terms of the COPYING file. 1913498266Sopenharmony_ci * 2013498266Sopenharmony_ci * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 2113498266Sopenharmony_ci * KIND, either express or implied. 2213498266Sopenharmony_ci * 2313498266Sopenharmony_ci * SPDX-License-Identifier: curl 2413498266Sopenharmony_ci * 2513498266Sopenharmony_ci ***************************************************************************/ 2613498266Sopenharmony_ci#include "curl_setup.h" 2713498266Sopenharmony_ci 2813498266Sopenharmony_ci#if defined(_WIN32) 2913498266Sopenharmony_ci 3013498266Sopenharmony_ci /* 3113498266Sopenharmony_ci * MultiByte conversions using Windows kernel32 library. 3213498266Sopenharmony_ci */ 3313498266Sopenharmony_ci 3413498266Sopenharmony_ciwchar_t *curlx_convert_UTF8_to_wchar(const char *str_utf8); 3513498266Sopenharmony_cichar *curlx_convert_wchar_to_UTF8(const wchar_t *str_w); 3613498266Sopenharmony_ci#endif /* _WIN32 */ 3713498266Sopenharmony_ci 3813498266Sopenharmony_ci/* 3913498266Sopenharmony_ci * Macros curlx_convert_UTF8_to_tchar(), curlx_convert_tchar_to_UTF8() 4013498266Sopenharmony_ci * and curlx_unicodefree() main purpose is to minimize the number of 4113498266Sopenharmony_ci * preprocessor conditional directives needed by code using these 4213498266Sopenharmony_ci * to differentiate UNICODE from non-UNICODE builds. 4313498266Sopenharmony_ci * 4413498266Sopenharmony_ci * In the case of a non-UNICODE build the tchar strings are char strings that 4513498266Sopenharmony_ci * are duplicated via strdup and remain in whatever the passed in encoding is, 4613498266Sopenharmony_ci * which is assumed to be UTF-8 but may be other encoding. Therefore the 4713498266Sopenharmony_ci * significance of the conversion functions is primarily for UNICODE builds. 4813498266Sopenharmony_ci * 4913498266Sopenharmony_ci * Allocated memory should be free'd with curlx_unicodefree(). 5013498266Sopenharmony_ci * 5113498266Sopenharmony_ci * Note: Because these are curlx functions their memory usage is not tracked 5213498266Sopenharmony_ci * by the curl memory tracker memdebug. You'll notice that curlx function-like 5313498266Sopenharmony_ci * macros call free and strdup in parentheses, eg (strdup)(ptr), and that's to 5413498266Sopenharmony_ci * ensure that the curl memdebug override macros do not replace them. 5513498266Sopenharmony_ci */ 5613498266Sopenharmony_ci 5713498266Sopenharmony_ci#if defined(UNICODE) && defined(_WIN32) 5813498266Sopenharmony_ci 5913498266Sopenharmony_ci#define curlx_convert_UTF8_to_tchar(ptr) curlx_convert_UTF8_to_wchar((ptr)) 6013498266Sopenharmony_ci#define curlx_convert_tchar_to_UTF8(ptr) curlx_convert_wchar_to_UTF8((ptr)) 6113498266Sopenharmony_ci 6213498266Sopenharmony_citypedef union { 6313498266Sopenharmony_ci unsigned short *tchar_ptr; 6413498266Sopenharmony_ci const unsigned short *const_tchar_ptr; 6513498266Sopenharmony_ci unsigned short *tbyte_ptr; 6613498266Sopenharmony_ci const unsigned short *const_tbyte_ptr; 6713498266Sopenharmony_ci} xcharp_u; 6813498266Sopenharmony_ci 6913498266Sopenharmony_ci#else 7013498266Sopenharmony_ci 7113498266Sopenharmony_ci#define curlx_convert_UTF8_to_tchar(ptr) (strdup)(ptr) 7213498266Sopenharmony_ci#define curlx_convert_tchar_to_UTF8(ptr) (strdup)(ptr) 7313498266Sopenharmony_ci 7413498266Sopenharmony_citypedef union { 7513498266Sopenharmony_ci char *tchar_ptr; 7613498266Sopenharmony_ci const char *const_tchar_ptr; 7713498266Sopenharmony_ci unsigned char *tbyte_ptr; 7813498266Sopenharmony_ci const unsigned char *const_tbyte_ptr; 7913498266Sopenharmony_ci} xcharp_u; 8013498266Sopenharmony_ci 8113498266Sopenharmony_ci#endif /* UNICODE && _WIN32 */ 8213498266Sopenharmony_ci 8313498266Sopenharmony_ci#define curlx_unicodefree(ptr) \ 8413498266Sopenharmony_ci do { \ 8513498266Sopenharmony_ci if(ptr) { \ 8613498266Sopenharmony_ci (free)(ptr); \ 8713498266Sopenharmony_ci (ptr) = NULL; \ 8813498266Sopenharmony_ci } \ 8913498266Sopenharmony_ci } while(0) 9013498266Sopenharmony_ci 9113498266Sopenharmony_ci#endif /* HEADER_CURL_MULTIBYTE_H */ 92