diff -r 5ab137def3d1 -r 408c66ad463d librazor/util.c --- a/librazor/util.c Fri Jan 27 08:12:19 2012 +0000 +++ b/librazor/util.c Sat Feb 11 09:34:40 2012 +0000 @@ -349,3 +349,39 @@ return un.machine; #endif } + +#ifdef MSWIN_API + +char *razor_utf16_to_utf8(const wchar_t *utf16, int len) +{ + int n; + char *utf8; + + n = WideCharToMultiByte(CP_UTF8, 0, utf16, len, NULL, 0, NULL, NULL); + if (len >= 0 && utf16[len]) + n++; + utf8 = malloc(n); + (void)WideCharToMultiByte(CP_UTF8, 0, utf16, len, utf8, n, NULL, NULL); + if (len >= 0 && utf16[len]) + utf8[n - 1] = 0; + + return utf8; +} + +wchar_t *razor_utf8_to_utf16(const char *utf8, int len) +{ + int n; + wchar_t *utf16; + + n = MultiByteToWideChar(CP_UTF8, 0, utf8, len, NULL, 0); + if (len >= 0 && utf8[len]) + n++; + utf16 = malloc(n * sizeof(wchar_t)); + (void)MultiByteToWideChar(CP_UTF8, 0, utf8, len, utf16, n); + if (len >= 0 && utf8[len]) + utf16[n - 1] = 0; + + return utf16; +} + +#endif /* MSWIN_API */