Nikolay Sivov nsivov@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.
lstrcpynA(dst, src, dstlen); return strlen(dst) + 1;
+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.
ret = WideCharToMultiByte(CP_ACP, 0, src, -1, dest, dest_len, NULL, NULL); if (!ret) dest[dest_len - 1] = 0; return dest_len;
If you have actual suggestion I'm sure nobody would mind if you posted it.
Sure.