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