diff options
author | Nikos Mavrogiannopoulos <nmav@redhat.com> | 2014-08-21 11:45:48 +0200 |
---|---|---|
committer | Nikos Mavrogiannopoulos <nmav@redhat.com> | 2014-08-21 11:45:48 +0200 |
commit | 29cd2ad3822e75b01d78dc617440d62832302dbd (patch) | |
tree | c77ca80f968944f03d8db1b3c9eea37915d6fd19 | |
parent | 70b0aac32f629a9fa4d784d7eecac5203c8c8b8f (diff) | |
download | gnutls-29cd2ad3822e75b01d78dc617440d62832302dbd.tar.gz |
use the windows API in windows even if iconv is available
-rw-r--r-- | lib/system.c | 107 |
1 files changed, 54 insertions, 53 deletions
diff --git a/lib/system.c b/lib/system.c index aea0ed2763..8d97929dd6 100644 --- a/lib/system.c +++ b/lib/system.c @@ -596,59 +596,7 @@ gnutls_x509_trust_list_add_system_trust(gnutls_x509_trust_list_t list, return add_system_trust(list, tl_flags, tl_vflags); } -#if defined(HAVE_ICONV) || defined(HAVE_LIBICONV) - -#include <iconv.h> - -int _gnutls_ucs2_to_utf8(const void *data, size_t size, - gnutls_datum_t * output) -{ - iconv_t conv; - int ret; - size_t orig, dstlen = size * 2; - char *src = (void *) data; - char *dst = NULL, *pdst; - - if (size == 0) - return gnutls_assert_val(GNUTLS_E_INVALID_REQUEST); - - conv = iconv_open("UTF-8", "UTF-16BE"); - if (conv == (iconv_t) - 1) - return gnutls_assert_val(GNUTLS_E_MEMORY_ERROR); - - /* Note that dstlen has enough size for every possible input characters. - * (remember the in UTF-16 the characters in data are at most size/2, - * and we allocate 4 bytes per character). - */ - pdst = dst = gnutls_malloc(dstlen + 1); - if (dst == NULL) { - ret = gnutls_assert_val(GNUTLS_E_MEMORY_ERROR); - goto fail; - } - - orig = dstlen; - ret = iconv(conv, &src, &size, &pdst, &dstlen); - if (ret == -1) { - ret = gnutls_assert_val(GNUTLS_E_PARSING_ERROR); - goto fail; - } - - output->data = (void *) dst; - output->size = orig - dstlen; - output->data[output->size] = 0; - - ret = 0; - goto cleanup; - - fail: - gnutls_free(dst); - - cleanup: - iconv_close(conv); - - return ret; -} -#elif defined(_WIN32) +#if defined(_WIN32) #include <winnls.h> /* Can convert only english */ @@ -712,6 +660,59 @@ int _gnutls_ucs2_to_utf8(const void *data, size_t size, return ret; } +#elif defined(HAVE_ICONV) || defined(HAVE_LIBICONV) + +#include <iconv.h> + +int _gnutls_ucs2_to_utf8(const void *data, size_t size, + gnutls_datum_t * output) +{ + iconv_t conv; + int ret; + size_t orig, dstlen = size * 2; + char *src = (void *) data; + char *dst = NULL, *pdst; + + if (size == 0) + return gnutls_assert_val(GNUTLS_E_INVALID_REQUEST); + + conv = iconv_open("UTF-8", "UTF-16BE"); + if (conv == (iconv_t) - 1) + return gnutls_assert_val(GNUTLS_E_MEMORY_ERROR); + + /* Note that dstlen has enough size for every possible input characters. + * (remember the in UTF-16 the characters in data are at most size/2, + * and we allocate 4 bytes per character). + */ + pdst = dst = gnutls_malloc(dstlen + 1); + if (dst == NULL) { + ret = gnutls_assert_val(GNUTLS_E_MEMORY_ERROR); + goto fail; + } + + orig = dstlen; + ret = iconv(conv, &src, &size, &pdst, &dstlen); + if (ret == -1) { + ret = gnutls_assert_val(GNUTLS_E_PARSING_ERROR); + goto fail; + } + + output->data = (void *) dst; + output->size = orig - dstlen; + output->data[output->size] = 0; + + ret = 0; + goto cleanup; + + fail: + gnutls_free(dst); + + cleanup: + iconv_close(conv); + + return ret; +} + #else /* Can convert only english (ASCII) */ |