1.1 --- a/librazor/util.c Fri Jan 27 08:12:19 2012 +0000
1.2 +++ b/librazor/util.c Thu Feb 09 20:45:27 2012 +0000
1.3 @@ -349,3 +349,39 @@
1.4 return un.machine;
1.5 #endif
1.6 }
1.7 +
1.8 +#ifdef MSWIN_API
1.9 +
1.10 +char *razor_utf16_to_utf8(const wchar_t *utf16, int len)
1.11 +{
1.12 + int n;
1.13 + char *utf8;
1.14 +
1.15 + n = WideCharToMultiByte(CP_UTF8, 0, utf16, len, NULL, 0, NULL, NULL);
1.16 + if (len >= 0 && utf16[len])
1.17 + n++;
1.18 + utf8 = malloc(n);
1.19 + (void)WideCharToMultiByte(CP_UTF8, 0, utf16, len, utf8, n, NULL, NULL);
1.20 + if (len >= 0 && utf16[len])
1.21 + utf8[n - 1] = 0;
1.22 +
1.23 + return utf8;
1.24 +}
1.25 +
1.26 +wchar_t *razor_utf8_to_utf16(const char *utf8, int len)
1.27 +{
1.28 + int n;
1.29 + wchar_t *utf16;
1.30 +
1.31 + n = MultiByteToWideChar(CP_UTF8, 0, utf8, len, NULL, 0);
1.32 + if (len >= 0 && utf8[len])
1.33 + n++;
1.34 + utf16 = malloc(n * sizeof(wchar_t));
1.35 + (void)MultiByteToWideChar(CP_UTF8, 0, utf8, len, utf16, n);
1.36 + if (len >= 0 && utf8[len])
1.37 + utf16[n - 1] = 0;
1.38 +
1.39 + return utf16;
1.40 +}
1.41 +
1.42 +#endif /* MSWIN_API */