Debian Codegraph @

upstream/debian-unstable/man3/mbstate_t.3type

raw
1 .\" Copyright, Bruno Haible <[email protected]>
2 .\" Copyright, the authors of the Linux man-pages project
3 .\"
4 .\" SPDX-License-Identifier: GPL-2.0-or-later
5 .\"
6 .TH mbstate_t 3type 2026-02-08 "Linux man-pages 6.18"
7 .SH NAME
8 mbstate_t
9 \-
10 multi-byte-character conversion state
11 .SH LIBRARY
12 Standard C library
13 .RI ( libc )
14 .SH SYNOPSIS
15 .nf
16 .B #include <wchar.h>
17 .P
18 .BR typedef " /* ... */ " mbstate_t;
19 .fi
20 .SH DESCRIPTION
21 Character conversion between
22 the multibyte representation
23 and the wide character representation
24 uses conversion state,
25 of type
26 .IR mbstate_t .
27 Conversion of a string uses a finite-state machine;
28 when it is interrupted after the complete conversion of a number of characters,
29 it may need to save a state for processing the remaining characters.
30 Such a conversion state
31 is needed for the sake of encodings such as ISO/IEC\~2022 and UTF-7.
32 .P
33 The initial state is the state at the beginning of conversion of a string.
34 There are two kinds of state:
35 the one used by multibyte to wide character conversion functions,
36 such as
37 .BR mbsrtowcs (3),
38 and the one used by wide character to multibyte conversion functions,
39 such as
40 .BR wcsrtombs (3),
41 but they both fit in a
42 .IR mbstate_t ,
43 and they both have the same representation for an initial state.
44 .P
45 For 8-bit encodings,
46 all states are equivalent to the initial state.
47 For multibyte encodings like UTF-8, EUC-*, BIG5, or SJIS,
48 the wide character to multibyte conversion functions
49 never produce non-initial states,
50 but the multibyte to wide-character conversion functions like
51 .BR mbrtowc (3)
52 do
53 produce non-initial states when interrupted in the middle of a character.
54 .P
55 One possible way to create an
56 .I mbstate_t
57 in initial state is to set it to zero:
58 .P
59 .in +4n
60 .EX
61 mbstate_t state;
62 memset(&state, 0, sizeof(state));
63 .EE
64 .in
65 .P
66 On Linux,
67 the following works as well,
68 but might generate compiler warnings:
69 .P
70 .in +4n
71 .EX
72 mbstate_t state = { 0 };
73 .EE
74 .in
75 .SH STANDARDS
76 C11, POSIX.1-2024.
77 .SH HISTORY
78 SUSv2,
79 C99, POSIX.1-2001.
80 .SH SEE ALSO
81 .BR mbrlen (3),
82 .BR mbrtowc (3),
83 .BR mbsinit (3),
84 .BR mbsrtowcs (3),
85 .BR wcrtomb (3),
86 .BR wcsrtombs (3)