Thread-safety of mbstowcs() and wcstombs()
Igor Liferenko
igor.liferenko@gmail.com
Fri Oct 7 07:17:00 GMT 2016
Some additional information:
I need to use mbstowcs and wcstombs functions, because sometimes I
need to convert a string in a program directly.
The examples are:
1) read filename from user, and then open the file.
The input is automatically transformed to UCS-4 internal encoding, but
filename must be in UTF-8 encoding.
2) or, the other way, read filenames in a directory and print them to the user.
The output is automatically transformed from UCS-4 internal encoding,
but filename is read in UTF-8 encoding.
Using mbsrtowcs and wcsrtombs is cumbersome for direct conversion,
because I have to manage two unneeded variables:
* I don't need to keep the last successfully
converted position, because all the strings
are already valid in my usage scenarios.
* I don't need to keep the state, because UTF-8 is
stateless encoding.
These two extra features are conveniently hidden by mbstowcs and
wcstombs, which greatly simplifies their direct usage in a program.
Again, the only problem with wcstombs and mbstowcs is that I'm not
sure how to tell if they are thread safe or not.
Igor
More information about the Libc-help
mailing list