curl_multibyte.c
Go to the documentation of this file.
00001 /***************************************************************************
00002  *                                  _   _ ____  _
00003  *  Project                     ___| | | |  _ \| |
00004  *                             / __| | | | |_) | |
00005  *                            | (__| |_| |  _ <| |___
00006  *                             \___|\___/|_| \_\_____|
00007  *
00008  * Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al.
00009  *
00010  * This software is licensed as described in the file COPYING, which
00011  * you should have received as part of this distribution. The terms
00012  * are also available at https://curl.haxx.se/docs/copyright.html.
00013  *
00014  * You may opt to use, copy, modify, merge, publish, distribute and/or sell
00015  * copies of the Software, and permit persons to whom the Software is
00016  * furnished to do so, under the terms of the COPYING file.
00017  *
00018  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
00019  * KIND, either express or implied.
00020  *
00021  ***************************************************************************/
00022 
00023 #include "curl_setup.h"
00024 
00025 #include <curl/curl.h>
00026 
00027 #if defined(USE_WIN32_IDN) || ((defined(USE_WINDOWS_SSPI) || \
00028                                 defined(USE_WIN32_LDAP)) && defined(UNICODE))
00029 
00030  /*
00031   * MultiByte conversions using Windows kernel32 library.
00032   */
00033 
00034 #include "curl_multibyte.h"
00035 #include "curl_memory.h"
00036 
00037 /* The last #include file should be: */
00038 #include "memdebug.h"
00039 
00040 wchar_t *Curl_convert_UTF8_to_wchar(const char *str_utf8)
00041 {
00042   wchar_t *str_w = NULL;
00043 
00044   if(str_utf8) {
00045     int str_w_len = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS,
00046                                         str_utf8, -1, NULL, 0);
00047     if(str_w_len > 0) {
00048       str_w = malloc(str_w_len * sizeof(wchar_t));
00049       if(str_w) {
00050         if(MultiByteToWideChar(CP_UTF8, 0, str_utf8, -1, str_w,
00051                                str_w_len) == 0) {
00052           free(str_w);
00053           return NULL;
00054         }
00055       }
00056     }
00057   }
00058 
00059   return str_w;
00060 }
00061 
00062 char *Curl_convert_wchar_to_UTF8(const wchar_t *str_w)
00063 {
00064   char *str_utf8 = NULL;
00065 
00066   if(str_w) {
00067     int str_utf8_len = WideCharToMultiByte(CP_UTF8, 0, str_w, -1, NULL,
00068                                            0, NULL, NULL);
00069     if(str_utf8_len > 0) {
00070       str_utf8 = malloc(str_utf8_len * sizeof(wchar_t));
00071       if(str_utf8) {
00072         if(WideCharToMultiByte(CP_UTF8, 0, str_w, -1, str_utf8, str_utf8_len,
00073                                NULL, FALSE) == 0) {
00074           free(str_utf8);
00075           return NULL;
00076         }
00077       }
00078     }
00079   }
00080 
00081   return str_utf8;
00082 }
00083 
00084 #endif /* USE_WIN32_IDN || ((USE_WINDOWS_SSPI || USE_WIN32_LDAP) && UNICODE) */


rc_visard_driver
Author(s): Heiko Hirschmueller , Christian Emmerich , Felix Ruess
autogenerated on Thu Jun 6 2019 20:43:02