curl_multibyte.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #ifndef HEADER_CURL_MULTIBYTE_H
  2. #define HEADER_CURL_MULTIBYTE_H
  3. /***************************************************************************
  4. * _ _ ____ _
  5. * Project ___| | | | _ \| |
  6. * / __| | | | |_) | |
  7. * | (__| |_| | _ <| |___
  8. * \___|\___/|_| \_\_____|
  9. *
  10. * Copyright (C) 1998 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al.
  11. *
  12. * This software is licensed as described in the file COPYING, which
  13. * you should have received as part of this distribution. The terms
  14. * are also available at https://curl.haxx.se/docs/copyright.html.
  15. *
  16. * You may opt to use, copy, modify, merge, publish, distribute and/or sell
  17. * copies of the Software, and permit persons to whom the Software is
  18. * furnished to do so, under the terms of the COPYING file.
  19. *
  20. * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  21. * KIND, either express or implied.
  22. *
  23. ***************************************************************************/
  24. #include "curl_setup.h"
  25. #if defined(WIN32)
  26. /*
  27. * MultiByte conversions using Windows kernel32 library.
  28. */
  29. wchar_t *curlx_convert_UTF8_to_wchar(const char *str_utf8);
  30. char *curlx_convert_wchar_to_UTF8(const wchar_t *str_w);
  31. #endif /* WIN32 */
  32. /*
  33. * Macros curlx_convert_UTF8_to_tchar(), curlx_convert_tchar_to_UTF8()
  34. * and curlx_unicodefree() main purpose is to minimize the number of
  35. * preprocessor conditional directives needed by code using these
  36. * to differentiate UNICODE from non-UNICODE builds.
  37. *
  38. * When building with UNICODE defined, these two macros
  39. * curlx_convert_UTF8_to_tchar() and curlx_convert_tchar_to_UTF8()
  40. * return a pointer to a newly allocated memory area holding result.
  41. * When the result is no longer needed, allocated memory is intended
  42. * to be free'ed with curlx_unicodefree().
  43. *
  44. * When building without UNICODE defined, this macros
  45. * curlx_convert_UTF8_to_tchar() and curlx_convert_tchar_to_UTF8()
  46. * return the pointer received as argument. curlx_unicodefree() does
  47. * no actual free'ing of this pointer it is simply set to NULL.
  48. */
  49. #if defined(UNICODE) && defined(WIN32)
  50. #define curlx_convert_UTF8_to_tchar(ptr) curlx_convert_UTF8_to_wchar((ptr))
  51. #define curlx_convert_tchar_to_UTF8(ptr) curlx_convert_wchar_to_UTF8((ptr))
  52. #define curlx_unicodefree(ptr) \
  53. do { \
  54. if(ptr) { \
  55. (free)(ptr); \
  56. (ptr) = NULL; \
  57. } \
  58. } while(0)
  59. typedef union {
  60. unsigned short *tchar_ptr;
  61. const unsigned short *const_tchar_ptr;
  62. unsigned short *tbyte_ptr;
  63. const unsigned short *const_tbyte_ptr;
  64. } xcharp_u;
  65. #else
  66. #define curlx_convert_UTF8_to_tchar(ptr) (ptr)
  67. #define curlx_convert_tchar_to_UTF8(ptr) (ptr)
  68. #define curlx_unicodefree(ptr) \
  69. do {(ptr) = NULL;} while(0)
  70. typedef union {
  71. char *tchar_ptr;
  72. const char *const_tchar_ptr;
  73. unsigned char *tbyte_ptr;
  74. const unsigned char *const_tbyte_ptr;
  75. } xcharp_u;
  76. #endif /* UNICODE && WIN32 */
  77. #endif /* HEADER_CURL_MULTIBYTE_H */