Converting from std::wstring to std::string in Linux
ssize_t is essentially unsigned; that is, the comparison res &gt;= 0 is always true.

The test should be

res != static_cast&lt;std::size_t&gt;(-1)

&lt;cstdlib&gt; and &lt;cwchar&gt; headers are missing
You don't need to WS.copy(wbuf, wlen).

In fact, you don't need wbuf at all:

const wchar_t * wptr = WS.c_str();
std::wcsrtombs(buf, &amp;wptr, sizeof(buf), &amp;st);


works just fine.
I am not sure that calculating buffer length via sizeof(std::wstring::value_type) is a right way. How can you be sure that multibyte sequence will fit? I'd recommend to obtain required size by passing NULL to wcsrtombs.


PS: И тебе привет