]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/mbsinit.3
MB_CUR_MAX.3, MB_LEN_MAX.3, btowc.3, fgetwc.3, fgetws.3, fputwc.3, fputws.3, fwide...
[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.\"
16.TH MBSINIT 3 2000-11-20 "GNU" "Linux Programmer's Manual"
17.SH NAME
18mbsinit \- test for initial shift state
19.SH SYNOPSIS
20.nf
21.B #include <wchar.h>
22.sp
23.BI "int mbsinit(const mbstate_t *" ps );
24.fi
25.SH DESCRIPTION
26Character conversion between the multibyte representation and the wide
381edf46 27character representation uses conversion state, of type \fImbstate_t\fP.
fea681da
MK
28Conversion of a string uses a finite-state machine; when it is interrupted
29after the complete conversion of a number of characters, it may need to
c13182ef
MK
30save a state for processing the remaining characters.
31Such a conversion
fea681da
MK
32state is needed for the sake of encodings such as ISO-2022 and UTF-7.
33.PP
34The initial state is the state at the beginning of conversion of a string.
35There are two kinds of state: The one used by multibyte to wide character
60a90ecd
MK
36conversion functions, such as
37.BR mbsrtowcs (3),
38and the one used by wide
39character to multibyte conversion functions, such as
40.BR wcsrtombs (3),
381edf46 41but they both fit in a \fImbstate_t\fP, and they both have the same
fea681da
MK
42representation for an initial state.
43.PP
44For 8-bit encodings, all states are equivalent to the initial state.
45For multibyte encodings like UTF-8, EUC-*, BIG5 or SJIS, the wide character
46to multibyte conversion functions never produce non-initial states, but the
60a90ecd
MK
47multibyte to wide-character conversion functions like
48.BR mbrtowc (3)
49do
fea681da
MK
50produce non-initial states when interrupted in the middle of a character.
51.PP
381edf46
MK
52One possible way to create an
53.I mbstate_t
54in initial state is to set it to zero:
fea681da 55.nf
381edf46
MK
56
57 mbstate_t state;
58 memset(&state,0,sizeof(mbstate_t));
fea681da 59.fi
381edf46 60.PP
fea681da
MK
61On Linux, the following works as well, but might generate compiler warnings:
62.nf
381edf46
MK
63
64 mbstate_t state = { 0 };
fea681da
MK
65.fi
66.PP
60a90ecd
MK
67The function
68.BR mbsinit ()
69tests whether \fI*ps\fP corresponds to an
fea681da 70initial state.
47297adb 71.SH RETURN VALUE
60a90ecd 72.BR mbsinit ()
c7094399 73returns nonzero if \fI*ps\fP is an initial state, or if
ad3fd4c0 74\fIps\fP is a NULL pointer.
c13182ef 75Otherwise it returns 0.
47297adb 76.SH CONFORMING TO
44a2c328 77C99.
fea681da 78.SH NOTES
d9bfdb9c 79The behavior of
60a90ecd 80.BR mbsinit ()
1274071a
MK
81depends on the
82.B LC_CTYPE
83category of the
fea681da 84current locale.
47297adb 85.SH SEE ALSO
e37e3282
MK
86.BR mbsrtowcs (3),
87.BR wcsrtombs (3)