FreeBSD has giconv.h instead of iconv.h.
[mono.git] / mono / io-layer / unicode.c
1 #include <config.h>
2 #include <glib.h>
3 #include <pthread.h>
4 #if HAVE_ICONV_H
5 #include <iconv.h>
6 #elif HAVE_GICONV_H
7 #include <giconv.h>
8 #endif
9 #include <errno.h>
10
11 #include "mono/io-layer/wapi.h"
12 #include "unicode.h"
13
14 /* This is a nasty kludge */
15 static guint32 
16 unicode_len (const gunichar2 *str)
17 {
18         guint32 len = 0;
19         
20         do {
21                 if (str [len] == '\0')
22                         return len * 2;
23
24                 len++;
25         } while (1);
26 }
27
28 gchar *_wapi_unicode_to_utf8(const gunichar2 *uni)
29 {
30         GError *error = NULL;
31         gchar *res;
32         int len;
33
34         len = unicode_len(uni);
35         
36         res = g_utf16_to_utf8 (uni, len, NULL, NULL, &error);
37
38         g_assert (!error);
39
40         return res;
41 }