summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikos Mavrogiannopoulos <nmav@redhat.com>2014-08-21 11:45:48 +0200
committerNikos Mavrogiannopoulos <nmav@redhat.com>2014-08-21 11:48:47 +0200
commitfee606130fcad767843ac627ba23e8d9c1012094 (patch)
treee76f7bc65b1f137e9684de6e87d487c3dcf87de8
parenta1d27cf387ded05efc671d9ca414c15d4a7a0bc5 (diff)
downloadgnutls-fee606130fcad767843ac627ba23e8d9c1012094.tar.gz
use the windows API in windows even if iconv is available
-rw-r--r--lib/system.c107
1 files changed, 54 insertions, 53 deletions
diff --git a/lib/system.c b/lib/system.c
index 1c71bf65fb..0868298c8a 100644
--- a/lib/system.c
+++ b/lib/system.c
@@ -563,59 +563,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 */
@@ -679,6 +627,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) */