]>
Commit | Line | Data |
---|---|---|
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 |
13 | mbsinit \- test for initial shift state | |
06a9444c AC |
14 | .SH LIBRARY |
15 | Standard 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 | |
24 | Character conversion between the multibyte representation and the wide | |
c6fa0841 MK |
25 | character representation uses conversion state, of type |
26 | .IR mbstate_t . | |
fea681da MK |
27 | Conversion of a string uses a finite-state machine; when it is interrupted |
28 | after the complete conversion of a number of characters, it may need to | |
c13182ef MK |
29 | save a state for processing the remaining characters. |
30 | Such a conversion | |
fea681da MK |
31 | state is needed for the sake of encodings such as ISO-2022 and UTF-7. |
32 | .PP | |
33 | The initial state is the state at the beginning of conversion of a string. | |
f64cc745 | 34 | There are two kinds of state: the one used by multibyte to wide character |
60a90ecd MK |
35 | conversion functions, such as |
36 | .BR mbsrtowcs (3), | |
37 | and the one used by wide | |
38 | character to multibyte conversion functions, such as | |
39 | .BR wcsrtombs (3), | |
c6fa0841 MK |
40 | but they both fit in a |
41 | .IR mbstate_t , | |
42 | and they both have the same | |
fea681da MK |
43 | representation for an initial state. |
44 | .PP | |
45 | For 8-bit encodings, all states are equivalent to the initial state. | |
735334d4 | 46 | For multibyte encodings like UTF-8, EUC-*, BIG5, or SJIS, the wide character |
fea681da | 47 | to multibyte conversion functions never produce non-initial states, but the |
60a90ecd MK |
48 | multibyte to wide-character conversion functions like |
49 | .BR mbrtowc (3) | |
50 | do | |
fea681da MK |
51 | produce non-initial states when interrupted in the middle of a character. |
52 | .PP | |
381edf46 MK |
53 | One possible way to create an |
54 | .I mbstate_t | |
55 | in initial state is to set it to zero: | |
207050fa MK |
56 | .PP |
57 | .in +4n | |
58 | .EX | |
59 | mbstate_t state; | |
7c813ea5 | 60 | memset(&state, 0, sizeof(state)); |
207050fa MK |
61 | .EE |
62 | .in | |
381edf46 | 63 | .PP |
fea681da | 64 | On Linux, the following works as well, but might generate compiler warnings: |
207050fa MK |
65 | .PP |
66 | .in +4n | |
67 | .EX | |
68 | mbstate_t state = { 0 }; | |
69 | .EE | |
70 | .in | |
fea681da | 71 | .PP |
60a90ecd MK |
72 | The function |
73 | .BR mbsinit () | |
c6fa0841 MK |
74 | tests whether |
75 | .I *ps | |
76 | corresponds to an | |
fea681da | 77 | initial state. |
47297adb | 78 | .SH RETURN VALUE |
60a90ecd | 79 | .BR mbsinit () |
c6fa0841 MK |
80 | returns nonzero if |
81 | .I *ps | |
82 | is an initial state, or if | |
83 | .I ps | |
b437fdd9 | 84 | is NULL. |
2b9b829d | 85 | Otherwise, it returns 0. |
ed0b5a78 | 86 | .SH ATTRIBUTES |
98769b12 PH |
87 | For 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 |
92 | allbox; | |
c466875e | 93 | lbx lb lb |
98769b12 PH |
94 | l l l. |
95 | Interface Attribute Value | |
96 | T{ | |
ed0b5a78 | 97 | .BR mbsinit () |
98769b12 PH |
98 | T} Thread safety MT-Safe |
99 | .TE | |
c466875e MK |
100 | .hy |
101 | .ad | |
102 | .sp 1 | |
3113c7f3 | 103 | .SH STANDARDS |
7937cf15 | 104 | POSIX.1-2001, POSIX.1-2008, C99. |
fea681da | 105 | .SH NOTES |
d9bfdb9c | 106 | The behavior of |
60a90ecd | 107 | .BR mbsinit () |
1274071a MK |
108 | depends on the |
109 | .B LC_CTYPE | |
110 | category of the | |
fea681da | 111 | current 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) |