man-pages/man3/mbsinit.3.html
2021-03-31 01:06:50 +01:00

183 lines
4.4 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML><HEAD><TITLE>Man page of MBSINIT</TITLE>
</HEAD><BODY>
<H1>MBSINIT</H1>
Section: Linux Programmer's Manual (3)<BR>Updated: 2016-10-08<BR><A HREF="#index">Index</A>
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
<A NAME="lbAB">&nbsp;</A>
<H2>NAME</H2>
mbsinit - test for initial shift state
<A NAME="lbAC">&nbsp;</A>
<H2>SYNOPSIS</H2>
<PRE>
<B>#include &lt;<A HREF="file:///usr/include/wchar.h">wchar.h</A>&gt;</B>
<B>int mbsinit(const mbstate_t *</B><I>ps</I><B>);</B>
</PRE>
<A NAME="lbAD">&nbsp;</A>
<H2>DESCRIPTION</H2>
Character conversion between the multibyte representation and the wide
character representation uses conversion state, of type
<I>mbstate_t</I>.
Conversion of a string uses a finite-state machine; when it is interrupted
after the complete conversion of a number of characters, it may need to
save a state for processing the remaining characters.
Such a conversion
state is needed for the sake of encodings such as ISO-2022 and UTF-7.
<P>
The initial state is the state at the beginning of conversion of a string.
There are two kinds of state: the one used by multibyte to wide character
conversion functions, such as
<B><A HREF="/cgi-bin/man/man2html?3+mbsrtowcs">mbsrtowcs</A></B>(3),
and the one used by wide
character to multibyte conversion functions, such as
<B><A HREF="/cgi-bin/man/man2html?3+wcsrtombs">wcsrtombs</A></B>(3),
but they both fit in a
<I>mbstate_t</I>,
and they both have the same
representation for an initial state.
<P>
For 8-bit encodings, all states are equivalent to the initial state.
For multibyte encodings like UTF-8, EUC-*, BIG5 or SJIS, the wide character
to multibyte conversion functions never produce non-initial states, but the
multibyte to wide-character conversion functions like
<B><A HREF="/cgi-bin/man/man2html?3+mbrtowc">mbrtowc</A></B>(3)
do
produce non-initial states when interrupted in the middle of a character.
<P>
One possible way to create an
<I>mbstate_t</I>
in initial state is to set it to zero:
<P>
mbstate_t state;
memset(&amp;state,0,sizeof(mbstate_t));
<P>
On Linux, the following works as well, but might generate compiler warnings:
<P>
mbstate_t state = { 0 };
<P>
The function
<B>mbsinit</B>()
tests whether
<I>*ps</I>
corresponds to an
initial state.
<A NAME="lbAE">&nbsp;</A>
<H2>RETURN VALUE</H2>
<B>mbsinit</B>()
returns nonzero if
<I>*ps</I>
is an initial state, or if
<I>ps</I>
is NULL.
Otherwise, it returns 0.
<A NAME="lbAF">&nbsp;</A>
<H2>ATTRIBUTES</H2>
For an explanation of the terms used in this section, see
<B><A HREF="/cgi-bin/man/man2html?7+attributes">attributes</A></B>(7).
<TABLE BORDER>
<TR VALIGN=top><TD><B>Interface</B></TD><TD><B>Attribute</B></TD><TD><B>Value</B><BR></TD></TR>
<TR VALIGN=top><TD>
<B>mbsinit</B>()
</TD><TD>Thread safety</TD><TD>MT-Safe<BR></TD></TR>
</TABLE>
<A NAME="lbAG">&nbsp;</A>
<H2>CONFORMING TO</H2>
POSIX.1-2001, POSIX.1-2008, C99.
<A NAME="lbAH">&nbsp;</A>
<H2>NOTES</H2>
The behavior of
<B>mbsinit</B>()
depends on the
<B>LC_CTYPE</B>
category of the
current locale.
<A NAME="lbAI">&nbsp;</A>
<H2>SEE ALSO</H2>
<B><A HREF="/cgi-bin/man/man2html?3+mbrlen">mbrlen</A></B>(3),
<B><A HREF="/cgi-bin/man/man2html?3+mbrtowc">mbrtowc</A></B>(3),
<B><A HREF="/cgi-bin/man/man2html?3+mbsrtowcs">mbsrtowcs</A></B>(3),
<B><A HREF="/cgi-bin/man/man2html?3+wcrtomb">wcrtomb</A></B>(3),
<B><A HREF="/cgi-bin/man/man2html?3+wcsrtombs">wcsrtombs</A></B>(3)
<A NAME="lbAJ">&nbsp;</A>
<H2>COLOPHON</H2>
This page is part of release 5.05 of the Linux
<I>man-pages</I>
project.
A description of the project,
information about reporting bugs,
and the latest version of this page,
can be found at
<A HREF="https://www.kernel.org/doc/man-pages/.">https://www.kernel.org/doc/man-pages/.</A>
<P>
<HR>
<A NAME="index">&nbsp;</A><H2>Index</H2>
<DL>
<DT id="1"><A HREF="#lbAB">NAME</A><DD>
<DT id="2"><A HREF="#lbAC">SYNOPSIS</A><DD>
<DT id="3"><A HREF="#lbAD">DESCRIPTION</A><DD>
<DT id="4"><A HREF="#lbAE">RETURN VALUE</A><DD>
<DT id="5"><A HREF="#lbAF">ATTRIBUTES</A><DD>
<DT id="6"><A HREF="#lbAG">CONFORMING TO</A><DD>
<DT id="7"><A HREF="#lbAH">NOTES</A><DD>
<DT id="8"><A HREF="#lbAI">SEE ALSO</A><DD>
<DT id="9"><A HREF="#lbAJ">COLOPHON</A><DD>
</DL>
<HR>
This document was created by
<A HREF="/cgi-bin/man/man2html">man2html</A>,
using the manual pages.<BR>
Time: 00:05:48 GMT, March 31, 2021
</BODY>
</HTML>