- utf16lechar *name_utf16le;
- size_t name_utf16le_nbytes;
- int ret;
-#if TCHAR_IS_UTF16LE
- name_utf16le_nbytes = tstrlen(name) * sizeof(utf16lechar);
- name_utf16le = MALLOC(name_utf16le_nbytes + sizeof(utf16lechar));
- if (name_utf16le == NULL)
- return WIMLIB_ERR_NOMEM;
- memcpy(name_utf16le, name, name_utf16le_nbytes + sizeof(utf16lechar));
- ret = 0;
-#else
-
- ret = tstr_to_utf16le(name, tstrlen(name), &name_utf16le,
- &name_utf16le_nbytes);
- if (ret == 0) {
- if (name_utf16le_nbytes > 0xffff) {
- FREE(name_utf16le);
- ERROR("Multibyte string \"%"TS"\" is too long!", name);
- ret = WIMLIB_ERR_INVALID_UTF8_STRING;
- }
+ utf16lechar *dup = MALLOC(usize + sizeof(utf16lechar));
+ if (dup) {
+ memcpy(dup, ustr, usize);
+ dup[usize / sizeof(utf16lechar)] = 0;