2 .\" Copyright (c) Bruno Haible <haible@clisp.cons.org>
4 .\" SPDX-License-Identifier: GPL-2.0-or-later
6 .\" References consulted:
7 .\" GNU glibc-2 source code and manual
8 .\" Dinkumware C library reference http://www.dinkumware.com/
9 .\" OpenGroup's Single UNIX specification http://www.UNIX-systems.org/online.html
12 .TH mbsinit 3 (date) "Linux man-pages (unreleased)"
14 mbsinit \- test for initial shift state
17 .RI ( libc ", " \-lc )
22 .BI "int mbsinit(const mbstate_t *" ps );
25 Character conversion between the multibyte representation and the wide
26 character representation uses conversion state, of type
28 Conversion of a string uses a finite-state machine; when it is interrupted
29 after the complete conversion of a number of characters, it may need to
30 save a state for processing the remaining characters.
32 state is needed for the sake of encodings such as ISO-2022 and UTF-7.
34 The initial state is the state at the beginning of conversion of a string.
35 There are two kinds of state: the one used by multibyte to wide character
36 conversion functions, such as
38 and the one used by wide
39 character to multibyte conversion functions, such as
41 but they both fit in a
43 and they both have the same
44 representation for an initial state.
46 For 8-bit encodings, all states are equivalent to the initial state.
47 For multibyte encodings like UTF-8, EUC-*, BIG5, or SJIS, the wide character
48 to multibyte conversion functions never produce non-initial states, but the
49 multibyte to wide-character conversion functions like
52 produce non-initial states when interrupted in the middle of a character.
54 One possible way to create an
56 in initial state is to set it to zero:
61 memset(&state, 0, sizeof(state));
65 On Linux, the following works as well, but might generate compiler warnings:
69 mbstate_t state = { 0 };
83 is an initial state, or if
86 Otherwise, it returns 0.
88 For an explanation of the terms used in this section, see
94 Interface Attribute Value
99 T} Thread safety MT-Safe