MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / utf8_to_wchar_t

Function utf8_to_wchar_t

lib/hidapi/linux/hid.c:104–123  ·  view source on GitHub ↗

The caller must free the returned string with free(). */

Source from the content-addressed store, hash-verified

102
103/* The caller must free the returned string with free(). */
104static 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

Callers 3

register_error_strFunction · 0.70
copy_udev_stringFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected