]>
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 | .\" | |
b8efb414 | 16 | .TH MBTOWC 3 2016-10-08 "GNU" "Linux Programmer's Manual" |
fea681da MK |
17 | .SH NAME |
18 | mbtowc \- convert a multibyte sequence to a wide character | |
19 | .SH SYNOPSIS | |
20 | .nf | |
21 | .B #include <stdlib.h> | |
68e4db0a | 22 | .PP |
fea681da MK |
23 | .BI "int mbtowc(wchar_t *" pwc ", const char *" s ", size_t " n ); |
24 | .fi | |
25 | .SH DESCRIPTION | |
40aa0db0 | 26 | The main case for this function is when |
51700fd7 | 27 | .IR s |
40aa0db0 MK |
28 | is not NULL and |
29 | .I pwc | |
30 | is | |
c13182ef | 31 | not NULL. |
60a90ecd MK |
32 | In this case, the |
33 | .BR mbtowc () | |
40aa0db0 MK |
34 | function inspects at most |
35 | .I n | |
36 | bytes of the multibyte string starting at | |
37 | .IR s , | |
c13182ef | 38 | extracts the next complete |
fea681da | 39 | multibyte character, converts it to a wide character and stores it at |
40aa0db0 | 40 | .IR *pwc . |
33a0ccb2 | 41 | It updates an internal shift state known only to the |
d8165d5b | 42 | .BR mbtowc () |
c13182ef | 43 | function. |
40aa0db0 MK |
44 | If |
45 | .I s | |
46 | does not point to a null byte (\(aq\\0\(aq), it returns the number | |
47 | of bytes that were consumed from | |
48 | .IR s , | |
49 | otherwise it returns 0. | |
fea681da | 50 | .PP |
40aa0db0 | 51 | If the |
51700fd7 | 52 | .IR n |
40aa0db0 MK |
53 | bytes starting at |
54 | .I s | |
55 | do not contain a complete multibyte | |
60a90ecd MK |
56 | character, or if they contain an invalid multibyte sequence, |
57 | .BR mbtowc () | |
00e28710 | 58 | returns \-1. |
40aa0db0 MK |
59 | This can happen even if |
60 | .I n | |
61 | >= | |
62 | .IR MB_CUR_MAX , | |
fea681da MK |
63 | if the multibyte string contains redundant shift sequences. |
64 | .PP | |
40aa0db0 | 65 | A different case is when |
51700fd7 | 66 | .IR s |
40aa0db0 MK |
67 | is not NULL but |
68 | .I pwc | |
69 | is NULL. | |
1b0b840d | 70 | In this case, the |
60a90ecd | 71 | .BR mbtowc () |
5633d88a | 72 | function behaves as above, except that it does not |
fea681da MK |
73 | store the converted wide character in memory. |
74 | .PP | |
40aa0db0 MK |
75 | A third case is when |
76 | .I s | |
77 | is NULL. | |
78 | In this case, | |
51700fd7 | 79 | .IR pwc |
40aa0db0 MK |
80 | and |
81 | .I n | |
82 | are | |
c13182ef | 83 | ignored. |
60a90ecd MK |
84 | The |
85 | .BR mbtowc () | |
86 | function | |
008f1ecc | 87 | .\" The Dinkumware doc and the Single UNIX specification say this, but |
fea681da | 88 | .\" glibc doesn't implement this. |
c13182ef MK |
89 | resets the shift state, only known to this function, |
90 | to the initial state, and | |
c7094399 | 91 | returns nonzero if the encoding has nontrivial shift state, or zero if the |
fea681da | 92 | encoding is stateless. |
47297adb | 93 | .SH RETURN VALUE |
40aa0db0 MK |
94 | If |
95 | .I s | |
96 | is not NULL, the | |
60a90ecd MK |
97 | .BR mbtowc () |
98 | function returns the number of | |
40aa0db0 MK |
99 | consumed bytes starting at |
100 | .IR s , | |
101 | or 0 if | |
102 | .I s | |
103 | points to a null byte, | |
fea681da MK |
104 | or \-1 upon failure. |
105 | .PP | |
40aa0db0 MK |
106 | If |
107 | .I s | |
108 | is NULL, the | |
60a90ecd MK |
109 | .BR mbtowc () |
110 | function | |
c7094399 | 111 | returns nonzero if the encoding |
c382a365 | 112 | has nontrivial shift state, or zero if the encoding is stateless. |
447b280d PH |
113 | .SH ATTRIBUTES |
114 | For an explanation of the terms used in this section, see | |
115 | .BR attributes (7). | |
116 | .TS | |
117 | allbox; | |
118 | lb lb lb | |
119 | l l l. | |
120 | Interface Attribute Value | |
121 | T{ | |
122 | .BR mbtowc () | |
9644042f | 123 | T} Thread safety MT-Unsafe race |
447b280d | 124 | .TE |
47297adb | 125 | .SH CONFORMING TO |
c28537ad | 126 | POSIX.1-2001, POSIX.1-2008, C99. |
fea681da | 127 | .SH NOTES |
d9bfdb9c | 128 | The behavior of |
60a90ecd | 129 | .BR mbtowc () |
1274071a MK |
130 | depends on the |
131 | .B LC_CTYPE | |
132 | category of the | |
fea681da MK |
133 | current locale. |
134 | .PP | |
71fea607 | 135 | This function is not multithread safe. |
60a90ecd MK |
136 | The function |
137 | .BR mbrtowc (3) | |
138 | provides | |
fea681da | 139 | a better interface to the same functionality. |
47297adb | 140 | .SH SEE ALSO |
e37e3282 | 141 | .BR MB_CUR_MAX (3), |
9247e95b | 142 | .BR mblen (3), |
e37e3282 | 143 | .BR mbrtowc (3), |
9247e95b | 144 | .BR mbstowcs (3), |
2e94784d MK |
145 | .BR wcstombs (3), |
146 | .BR wctomb (3) |