This is the mail archive of the
libc-help@sourceware.org
mailing list for the glibc project.
Re: Thread-safety of mbstowcs() and wcstombs()
- From: Igor Liferenko <igor dot liferenko at gmail dot com>
- To: libc-help at sourceware dot org
- Date: Fri, 7 Oct 2016 14:17:29 +0700
- Subject: Re: Thread-safety of mbstowcs() and wcstombs()
- Authentication-results: sourceware.org; auth=none
- References: <CAJyx361h03CYr9k9d_K7Vuw20tiZ3s7jibjbozdu5ZSM=xVBcg@mail.gmail.com>
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