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