]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/mbsinit.3
All pages: Replace the 4th argument to .TH by "Linux man-pages (unreleased)"
[thirdparty/man-pages.git] / man3 / mbsinit.3
CommitLineData
fea681da
MK
1.\" Copyright (c) Bruno Haible <haible@clisp.cons.org>
2.\"
e4a74ca8 3.\" SPDX-License-Identifier: GPL-2.0-or-later
fea681da
MK
4.\"
5.\" References consulted:
6.\" GNU glibc-2 source code and manual
7.\" Dinkumware C library reference http://www.dinkumware.com/
008f1ecc 8.\" OpenGroup's Single UNIX specification http://www.UNIX-systems.org/online.html
fea681da
MK
9.\" ISO/IEC 9899:1999
10.\"
7bd6328f 11.TH MBSINIT 3 2021-03-22 "Linux man-pages (unreleased)" "Linux Programmer's Manual"
fea681da
MK
12.SH NAME
13mbsinit \- test for initial shift state
06a9444c
AC
14.SH LIBRARY
15Standard C library
8fc3b2cf 16.RI ( libc ", " \-lc )
fea681da
MK
17.SH SYNOPSIS
18.nf
19.B #include <wchar.h>
68e4db0a 20.PP
fea681da
MK
21.BI "int mbsinit(const mbstate_t *" ps );
22.fi
23.SH DESCRIPTION
24Character conversion between the multibyte representation and the wide
c6fa0841
MK
25character representation uses conversion state, of type
26.IR mbstate_t .
fea681da
MK
27Conversion of a string uses a finite-state machine; when it is interrupted
28after the complete conversion of a number of characters, it may need to
c13182ef
MK
29save a state for processing the remaining characters.
30Such a conversion
fea681da
MK
31state is needed for the sake of encodings such as ISO-2022 and UTF-7.
32.PP
33The initial state is the state at the beginning of conversion of a string.
f64cc745 34There are two kinds of state: the one used by multibyte to wide character
60a90ecd
MK
35conversion functions, such as
36.BR mbsrtowcs (3),
37and the one used by wide
38character to multibyte conversion functions, such as
39.BR wcsrtombs (3),
c6fa0841
MK
40but they both fit in a
41.IR mbstate_t ,
42and they both have the same
fea681da
MK
43representation for an initial state.
44.PP
45For 8-bit encodings, all states are equivalent to the initial state.
735334d4 46For multibyte encodings like UTF-8, EUC-*, BIG5, or SJIS, the wide character
fea681da 47to multibyte conversion functions never produce non-initial states, but the
60a90ecd
MK
48multibyte to wide-character conversion functions like
49.BR mbrtowc (3)
50do
fea681da
MK
51produce non-initial states when interrupted in the middle of a character.
52.PP
381edf46
MK
53One possible way to create an
54.I mbstate_t
55in initial state is to set it to zero:
207050fa
MK
56.PP
57.in +4n
58.EX
59mbstate_t state;
7c813ea5 60memset(&state, 0, sizeof(state));
207050fa
MK
61.EE
62.in
381edf46 63.PP
fea681da 64On Linux, the following works as well, but might generate compiler warnings:
207050fa
MK
65.PP
66.in +4n
67.EX
68mbstate_t state = { 0 };
69.EE
70.in
fea681da 71.PP
60a90ecd
MK
72The function
73.BR mbsinit ()
c6fa0841
MK
74tests whether
75.I *ps
76corresponds to an
fea681da 77initial state.
47297adb 78.SH RETURN VALUE
60a90ecd 79.BR mbsinit ()
c6fa0841
MK
80returns nonzero if
81.I *ps
82is an initial state, or if
83.I ps
b437fdd9 84is NULL.
2b9b829d 85Otherwise, it returns 0.
ed0b5a78 86.SH ATTRIBUTES
98769b12
PH
87For an explanation of the terms used in this section, see
88.BR attributes (7).
c466875e
MK
89.ad l
90.nh
98769b12
PH
91.TS
92allbox;
c466875e 93lbx lb lb
98769b12
PH
94l l l.
95Interface Attribute Value
96T{
ed0b5a78 97.BR mbsinit ()
98769b12
PH
98T} Thread safety MT-Safe
99.TE
c466875e
MK
100.hy
101.ad
102.sp 1
3113c7f3 103.SH STANDARDS
7937cf15 104POSIX.1-2001, POSIX.1-2008, C99.
fea681da 105.SH NOTES
d9bfdb9c 106The behavior of
60a90ecd 107.BR mbsinit ()
1274071a
MK
108depends on the
109.B LC_CTYPE
110category of the
fea681da 111current locale.
47297adb 112.SH SEE ALSO
35b07818
MK
113.BR mbrlen (3),
114.BR mbrtowc (3),
e37e3282 115.BR mbsrtowcs (3),
13bc1e78 116.BR wcrtomb (3),
e37e3282 117.BR wcsrtombs (3)