On 06/21/16 12:37, Hugh McMaster wrote:
On Tuesday, 21 June 2016 7:04 PM UTC+10, Piotr Caban wrote:
This is not how the function works. It shouldn't print wchar_t string to stderr. Probably the simplest implementation is to convert input parameter and call _perror (CP_ACP is not the correct encoding, you can use MSVCRT_wcstombs).
I don't understand. The MSDN page [1] contradicts your statement. "The perror function prints an error message to stderr. _wperror is a wide-character version of _perror; the string argument to _wperror is a wide-character string. _wperror and _perror behave identically otherwise."
The function is not writing wide-characters to stderr. It can be easily tested, e.g. do something like this: freopen("test.txt", "wb", stderr); errno = 3; _wperror(L"test"); and see what's in the file when run on Windows/with your implementation. It will also display incorrectly when _wperror is run inside wine's cmd window.
Also, if we convert the wide string to multibyte, there is a risk any non-Unicode characters supplied as input will not display correctly. So, IMHO converting to a multibyte string is a bad approach.
This is something that is worth testing. Anyway the conversion needs to be done.
Still, if that's what you want, I'll do it.
I want the function to be implemented correctly.
Thanks, Piotr