]>
Commit | Line | Data |
---|---|---|
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 | .\" | |
460495ca | 16 | .TH MBSINIT 3 2015-08-08 "GNU" "Linux Programmer's Manual" |
fea681da MK |
17 | .SH NAME |
18 | mbsinit \- 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 | |
26 | Character conversion between the multibyte representation and the wide | |
c6fa0841 MK |
27 | character representation uses conversion state, of type |
28 | .IR mbstate_t . | |
fea681da MK |
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 | |
c13182ef MK |
31 | save a state for processing the remaining characters. |
32 | Such a conversion | |
fea681da MK |
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 | |
60a90ecd MK |
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), | |
c6fa0841 MK |
42 | but they both fit in a |
43 | .IR mbstate_t , | |
44 | and they both have the same | |
fea681da MK |
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 | |
60a90ecd MK |
50 | multibyte to wide-character conversion functions like |
51 | .BR mbrtowc (3) | |
52 | do | |
fea681da MK |
53 | produce non-initial states when interrupted in the middle of a character. |
54 | .PP | |
381edf46 MK |
55 | One possible way to create an |
56 | .I mbstate_t | |
57 | in initial state is to set it to zero: | |
fea681da | 58 | .nf |
381edf46 MK |
59 | |
60 | mbstate_t state; | |
61 | memset(&state,0,sizeof(mbstate_t)); | |
fea681da | 62 | .fi |
381edf46 | 63 | .PP |
fea681da MK |
64 | On Linux, the following works as well, but might generate compiler warnings: |
65 | .nf | |
381edf46 MK |
66 | |
67 | mbstate_t state = { 0 }; | |
fea681da MK |
68 | .fi |
69 | .PP | |
60a90ecd MK |
70 | The function |
71 | .BR mbsinit () | |
c6fa0841 MK |
72 | tests whether |
73 | .I *ps | |
74 | corresponds to an | |
fea681da | 75 | initial state. |
47297adb | 76 | .SH RETURN VALUE |
60a90ecd | 77 | .BR mbsinit () |
c6fa0841 MK |
78 | returns nonzero if |
79 | .I *ps | |
80 | is an initial state, or if | |
81 | .I ps | |
b437fdd9 | 82 | is NULL. |
2b9b829d | 83 | Otherwise, it returns 0. |
ed0b5a78 | 84 | .SH ATTRIBUTES |
98769b12 PH |
85 | For an explanation of the terms used in this section, see |
86 | .BR attributes (7). | |
87 | .TS | |
88 | allbox; | |
89 | lb lb lb | |
90 | l l l. | |
91 | Interface Attribute Value | |
92 | T{ | |
ed0b5a78 | 93 | .BR mbsinit () |
98769b12 PH |
94 | T} Thread safety MT-Safe |
95 | .TE | |
47297adb | 96 | .SH CONFORMING TO |
7937cf15 | 97 | POSIX.1-2001, POSIX.1-2008, C99. |
fea681da | 98 | .SH NOTES |
d9bfdb9c | 99 | The behavior of |
60a90ecd | 100 | .BR mbsinit () |
1274071a MK |
101 | depends on the |
102 | .B LC_CTYPE | |
103 | category of the | |
fea681da | 104 | current locale. |
47297adb | 105 | .SH SEE ALSO |
35b07818 MK |
106 | .BR mbrlen (3), |
107 | .BR mbrtowc (3), | |
108 | .BR wcrtomb (3), | |
e37e3282 MK |
109 | .BR mbsrtowcs (3), |
110 | .BR wcsrtombs (3) |