mirror of
https://github.com/VARCem/MiniVHD.git
synced 2026-09-24 07:45:12 +00:00
Fixed string encoding (at least for Win)
This commit is contained in:
17
vhdutil.c
17
vhdutil.c
@@ -22,15 +22,14 @@ int vhd_utf_convert(VHDUtfType toUTF, void* in_str, char** out_str)
|
||||
out_buff_len = MultiByteToWideChar(CP_UTF8, 0, (LPCCH)in_str, -1, NULL, 0);
|
||||
out_type = sizeof(WCHAR);
|
||||
}
|
||||
char *out = *out_str;
|
||||
out = calloc(out_buff_len, out_type);
|
||||
if (out == NULL) {
|
||||
*out_str = calloc(out_buff_len, out_type);
|
||||
if (*out_str == NULL) {
|
||||
return -1;
|
||||
}
|
||||
if (toUTF == VHD_UTF_8) {
|
||||
WideCharToMultiByte(CP_UTF8, 0, (LPCWCH)in_str, -1, (LPSTR)out, out_buff_len, NULL, NULL);
|
||||
WideCharToMultiByte(CP_UTF8, 0, (LPCWCH)in_str, -1, (LPSTR)*out_str, out_buff_len, NULL, NULL);
|
||||
} else {
|
||||
MultiByteToWideChar(CP_UTF8, 0, (LPCCH)in_str, -1, (LPWSTR)out, out_buff_len);
|
||||
MultiByteToWideChar(CP_UTF8, 0, (LPCCH)in_str, -1, (LPWSTR)*out_str, out_buff_len);
|
||||
}
|
||||
#else
|
||||
iconv_t cd = (toUTF == VHD_UTF_8) ? iconv_open("UTF-8", "UTF-16LE") : iconv_open("UTF-16LE", "UTF-8");
|
||||
@@ -39,16 +38,16 @@ int vhd_utf_convert(VHDUtfType toUTF, void* in_str, char** out_str)
|
||||
char *in = (char*)in_str;
|
||||
size_t in_len = (toUTF == VHD_UTF_8) ? (vhd_u16_strlen(in) * sizeof(uint16_t)) : strlen(in);
|
||||
size_t out_len = (toUTF == VHD_UTF_8) ? ((in_len * 2) + 1) : ((in_len * 4) + 2);
|
||||
char *out = *out_str;
|
||||
out = calloc(out_len, sizeof *out);
|
||||
if (out == NULL) {
|
||||
*out_str = calloc(out_len, sizeof **out_str);
|
||||
if (*out_str == NULL) {
|
||||
return -1;
|
||||
}
|
||||
size_t res = iconv(cd, &in, &in_len, &out, &out_len);
|
||||
size_t res = iconv(cd, &in, &in_len, &*out_str, &out_len);
|
||||
if (res == (size_t)-1) {
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t vhd_u16_strlen(uint16_t* u16_str) {
|
||||
|
||||
Reference in New Issue
Block a user