Question

I'm attempting to convert a wchar_t* to a char*. Here's my code:

size_t result = wcstombs(returned, str, length + 1);
if (result == (size_t)-1) {
    int error = errno;
}

It indeed fails, and error is filled with 92 (ENOPROTOOPT) - Protocol not available.

I've even tried setting the locale:

setlocale(LC_ALL, "C");

And this one too:

setlocale(LC_ALL, "");

I'm tempted to just throw the characters with static casts!

Was it helpful?

Solution

Seems the issue was that the source string was encoded with a non-standard encoding (two ASCII characters for each wide character), which looked fine in the debugger, but clearly internally was sour. The error code produced is clearly not documented, but it's the equivalent to simply not being able to decode said piece of text.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top