On 11/29/18 9:10 AM, Dmitry Timoshkov wrote:
Nikolay Sivov <nsivov(a)codeweavers.com> wrote:
+DWORD WINAPI SHAnsiToAnsi(const char *src, char *dest, int dest_len) +{ + DWORD ret = 0; + + TRACE("(%s, %p, %d)\n", debugstr_a(src), dest, dest_len); + + if (!src || !dest || dest_len <= 0) + return 0; + + while (dest_len > 1 && *src) + { + dest_len--; + *dest++ = *src++; + ret++; + } + + if (dest_len) + { + *dest = 0; + ret++; + } + + return ret; +} Still the same duplication without a reasonable explanation.
It's used to get correct return value.
+DWORD WINAPI SHUnicodeToAnsi(const WCHAR *src, char *dest, int dest_len) +{ + int required = 1; + + TRACE("(%s, %p, %d)\n", debugstr_w(src), dest, dest_len); + + if (!dest || !dest_len) + return 0; + + if (src) + { + required = WideCharToMultiByte(CP_ACP, 0, src, -1, NULL, 0, NULL, NULL); + WideCharToMultiByte(CP_ACP, 0, src, -1, dest, dest_len, NULL, NULL); It should be possible to avoid doing the conversion twice.
Second call returns 0 for shorter buffer. If you have actual suggestion I'm sure nobody would mind if you posted it.
Same comments apply for remaining implementations.