1 '\" te 2 .\" Copyright (c) 1992, X/Open Company Limited. All Rights Reserved. Portions Copyright (c) 2003, Sun Microsystems, Inc. All Rights Reserved. 3 .\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for permission to reproduce portions of its copyrighted documentation. Original documentation from The Open Group can be obtained online at 4 .\" http://www.opengroup.org/bookstore/. 5 .\" The Institute of Electrical and Electronics Engineers and The Open Group, have given us permission to reprint portions of their documentation. In the following statement, the phrase "this text" refers to portions of the system documentation. Portions of this text are reprinted and reproduced in electronic form in the Sun OS Reference Manual, from IEEE Std 1003.1, 2004 Edition, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 6, Copyright (C) 2001-2004 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between these versions and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html. 6 .\" This notice shall appear on any product containing this material. 7 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License. 8 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License. 9 .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner] 10 .TH MBRTOWC 3C "Nov 1, 2003" 11 .SH NAME 12 mbrtowc \- convert a character to a wide-character code (restartable) 13 .SH SYNOPSIS 14 .LP 15 .nf 16 #include <wchar.h> 17 18 \fBsize_t\fR \fBmbrtowc\fR(\fBwchar_t *restrict\fR \fIpwc\fR, \fBconst char *restrict\fR \fIs\fR, \fBsize_t\fR \fIn\fR, 19 \fBmbstate_t *restrict\fR \fIps\fR); 20 .fi 21 22 .SH DESCRIPTION 23 .sp 24 .LP 25 If \fIs\fR is a null pointer, the \fBmbrtowc()\fR function is equivalent to the 26 call: 27 .sp 28 .in +2 29 .nf 30 mbrtowc(NULL, ``'', 1, ps) 31 .fi 32 .in -2 33 34 .sp 35 .LP 36 In this case, the values of the arguments \fIpwc\fR and \fIn\fR are ignored. 37 .sp 38 .LP 39 If \fIs\fR is not a null pointer, the \fBmbrtowc()\fR function inspects at most 40 \fIn\fR bytes beginning at the byte pointed to by \fIs\fR to determine the 41 number of bytes needed to complete the next character (including any shift 42 sequences). If the function determines that the next character is completed, 43 it determines the value of the corresponding wide-character and then, if 44 \fIpwc\fR is not a null pointer, stores that value in the object pointed to by 45 \fIpwc\fR. If the corresponding wide-character is the null wide-character, the 46 resulting state described is the initial conversion state. 47 .sp 48 .LP 49 If \fIps\fR is a null pointer, the \fBmbrtowc()\fR function uses its own 50 internal \fBmbstate_t\fR object, which is initialized at program startup to the 51 initial conversion state. Otherwise, the \fBmbstate_t\fR object pointed to 52 by \fIps\fR is used to completely describe the current conversion state of the 53 associated character sequence. Solaris will behave as if no function defined in 54 the Solaris Reference Manual calls \fBmbrtowc()\fR. 55 .sp 56 .LP 57 The behavior of this function is affected by the \fBLC_CTYPE\fR category of the 58 current locale. See \fBenviron\fR(5). 59 .SH RETURN VALUES 60 .sp 61 .LP 62 The \fBmbrtowc()\fR function returns the first of the following that applies: 63 .sp 64 .ne 2 65 .na 66 \fB\fB0\fR\fR 67 .ad 68 .RS 17n 69 If the next \fIn\fR or fewer bytes complete the character that corresponds to 70 the null wide-character (which is the value stored). 71 .RE 72 73 .sp 74 .ne 2 75 .na 76 \fB\fBpositive\fR\fR 77 .ad 78 .RS 17n 79 If the next \fIn\fR or fewer bytes complete a valid character (which is the 80 value stored); the value returned is the number of bytes that complete the 81 character. 82 .RE 83 84 .sp 85 .ne 2 86 .na 87 \fB\fB(size_t)\(mi2\fR\fR 88 .ad 89 .RS 17n 90 If the next \fIn\fR bytes contribute to an incomplete but potentially valid 91 character, and all \fIn\fR bytes have been processed (no value is stored). 92 When \fIn\fR has at least the value of the \fBMB_CUR_MAX\fR macro, this case 93 can only occur if \fIs\fR points at a sequence of redundant shift sequences 94 (for implementations with state-dependent encodings). 95 .RE 96 97 .sp 98 .ne 2 99 .na 100 \fB\fB(size_t)\(mi1\fR\fR 101 .ad 102 .RS 17n 103 If an encoding error occurs, in which case the next \fIn\fR or fewer bytes do 104 not contribute to a complete and valid character (no value is stored). In 105 this case, \fBEILSEQ\fR is stored in \fBerrno\fR and the conversion state is 106 undefined. 107 .RE 108 109 .SH ERRORS 110 .sp 111 .LP 112 The \fBmbrtowc()\fR function may fail if: 113 .sp 114 .ne 2 115 .na 116 \fB\fBEINVAL\fR\fR 117 .ad 118 .RS 10n 119 The \fIps\fR argument points to an object that contains an invalid conversion 120 state. 121 .RE 122 123 .sp 124 .ne 2 125 .na 126 \fB\fBEILSEQ\fR\fR 127 .ad 128 .RS 10n 129 Invalid character sequence is detected. 130 .RE 131 132 .SH ATTRIBUTES 133 .sp 134 .LP 135 See \fBattributes\fR(5) for descriptions of the following attributes: 136 .sp 137 138 .sp 139 .TS 140 box; 141 c | c 142 l | l . 143 ATTRIBUTE TYPE ATTRIBUTE VALUE 144 _ 145 Interface Stability Standard 146 _ 147 MT-Level See NOTES below 148 .TE 149 150 .SH SEE ALSO 151 .sp 152 .LP 153 \fBmbsinit\fR(3C), \fBsetlocale\fR(3C), \fBattributes\fR(5), \fBenviron\fR(5), 154 \fBstandards\fR(5) 155 .SH NOTES 156 .sp 157 .LP 158 If \fIps\fR is not a null pointer, \fBmbrtowc()\fR uses the \fBmbstate_t\fR 159 object pointed to by \fIps\fR and the function can be used safely in 160 multithreaded applications, as long as \fBsetlocale\fR(3C) is not being called 161 to change the locale. If \fIps\fR is a null pointer, \fBmbrtowc()\fR uses its 162 internal \fBmbstate_t\fR object and the function is Unsafe in multithreaded 163 applications.