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