The caller must free the returned string with free(). */
| 102 | |
| 103 | /* The caller must free the returned string with free(). */ |
| 104 | static wchar_t *utf8_to_wchar_t(const char *utf8) |
| 105 | { |
| 106 | wchar_t *ret = NULL; |
| 107 | |
| 108 | if (utf8) { |
| 109 | size_t wlen = mbstowcs(NULL, utf8, 0); |
| 110 | if ((size_t) -1 == wlen) { |
| 111 | return wcsdup(L""); |
| 112 | } |
| 113 | ret = (wchar_t*) calloc(wlen+1, sizeof(wchar_t)); |
| 114 | if (ret == NULL) { |
| 115 | /* as much as we can do at this point */ |
| 116 | return NULL; |
| 117 | } |
| 118 | mbstowcs(ret, utf8, wlen+1); |
| 119 | ret[wlen] = 0x0000; |
| 120 | } |
| 121 | |
| 122 | return ret; |
| 123 | } |
| 124 | |
| 125 | |
| 126 | /* Makes a copy of the given error message (and decoded according to the |
no outgoing calls
no test coverage detected