1 '\" te
   2 .\" Copyright 2014 Garrett D'Amore <garrett@damore.org>
   3 .\" Copyright (c) 1992, X/Open Company Limited. All Rights Reserved.  Portions Copyright (c) 2003, Sun Microsystems, Inc.  All Rights Reserved.
   4 .\" 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
   5 .\" http://www.opengroup.org/bookstore/.
   6 .\" 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.
   7 .\"  This notice shall appear on any product containing this material.
   8 .\" 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.
   9 .\" 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.
  10 .\" 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]
  11 .TH MBRTOWC 3C "Jun 23, 2014"
  12 .SH NAME
  13 mbrtowc, mbrtowc_l \- convert a character to a wide-character code (restartable)
  14 .SH SYNOPSIS
  15 .LP
  16 .nf
  17 #include <wchar.h>
  18 
  19 \fBsize_t\fR \fBmbrtowc\fR(\fBwchar_t *restrict\fR \fIpwc\fR, \fBconst char *restrict\fR \fIs\fR, \fBsize_t\fR \fIn\fR,
  20      \fBmbstate_t *restrict\fR \fIps\fR);
  21 .fi
  22 .LP
  23 .nf
  24 #include <wchar.h>
  25 #include <xlocale.h>
  26 
  27 \fBsize_t\fR \fBmbrtowc_l\fR(\fBwchar_t *restrict\fR \fIpwc\fR, \fBconst char *restrict\fR \fIs\fR, \fBsize_t\fR \fIn\fR,
  28      \fBmbstate_t *restrict\fR \fIps\fR, \fBlocale_t\fR \fIloc\fR);
  29 .fi
  30 .SH DESCRIPTION
  31 .LP
  32 If
  33 .I s
  34 is a null pointer, the
  35 .B mbrtowc()
  36 function is equivalent to the call:
  37 .sp
  38 .in +2
  39 .nf
  40 \fBmbrtowc\fR(NULL, "", 1, \fIps\fR)
  41 .fi
  42 .in -2
  43 .LP
  44 Likewise, if
  45 .I s
  46 is a null pointer, the
  47 .B mbrtowc_l()
  48 function is equivalent to the call:
  49 .sp
  50 .in +2
  51 .nf
  52 \fBmbrtowc_l\fR(NULL, "", 1, \fIps\fR, \fIloc\fR);
  53 .fi
  54 .in -2
  55 .LP
  56 In these cases, the values of the arguments
  57 .I pwc
  58 and
  59 .I n
  60 are ignored.
  61 .LP
  62 If
  63 .I s
  64 is not a null pointer, these functions inspect at most
  65 .I n
  66 bytes beginning at the byte pointed to by
  67 .I s
  68 to determine the number of bytes needed to complete the next character
  69 (including any shift sequences).  If the functions determine that the next
  70 character is completed,
  71 they determine the value of the corresponding wide-character and then, if
  72 .I pwc
  73 is not a null pointer, stores that value in the object pointed to by
  74 .IR pwc .
  75 If the corresponding wide-character is the null wide-character, the
  76 resulting state described is the initial conversion state.
  77 .LP
  78 If
  79 .I ps
  80 is a null pointer, these functions use their own
  81 internal
  82 .B mbstate_t
  83 object, which is initialized at program startup to the
  84 initial conversion state. Otherwise, the 
  85 .B mbstate_t
  86 object pointed to by
  87 .I ps
  88 is used to completely describe the current conversion state of the
  89 associated character sequence. The system will behave as if no function defined
  90 in the Reference Manual calls
  91 .B mbrtowc()
  92 or
  93 .BR Bmbrtowc_l() .
  94 .LP
  95 The behavior of
  96 .B mbrtowc()
  97 is affected by the
  98 .B LC_CTYPE
  99 category of the current locale.  The
 100 .B mbrtowc_l()
 101 function is affected by the
 102 .B LC_CTYPE
 103 category of the specified
 104 .I loc
 105 locale object.  See
 106 .B environ (5).
 107 .SH RETURN VALUES
 108 .LP
 109 The
 110 .B mbrtowc()
 111 and
 112 .B mbrtowc_l()
 113 functions return the first of the following that applies:
 114 .IP \fB0\fR
 115 If the next
 116 .I n
 117 or fewer bytes complete the character that corresponds to
 118 the null wide-character (which is the value stored).
 119 .IP \fBpositive\fR
 120 If the next
 121 .I n
 122 or fewer bytes complete a valid character (which is the
 123 value stored); the value returned is the number of bytes that complete the
 124 character.
 125 .IP \fB(size_t)\(mi2\fR
 126 If the next
 127 .I n
 128 bytes contribute to an incomplete but potentially valid
 129 character, and all
 130 .I n
 131 bytes have been processed (no value is stored).
 132 When
 133 .I n
 134 has at least the value of the
 135 .B MB_CUR_MAX
 136 macro, this case can only occur if
 137 .I s
 138 points at a sequence of redundant shift sequences
 139 (for implementations with state-dependent encodings).
 140 .IP \fB(size_t)\(mi1\fR
 141 If an encoding error occurs, in which case the next \fIn\fR or fewer bytes do
 142 not contribute to a complete and valid  character (no value is stored).  In
 143 this case,
 144 .B EILSEQ
 145 is stored in
 146 .B errno
 147 and the conversion state is undefined.
 148 .SH ERRORS
 149 .LP
 150 The
 151 .B mbrtowc()
 152 and
 153 .B mbrtowc_l()
 154 functions may fail if:
 155 .IP \fBEINVAL\fR
 156 The
 157 .I ps
 158 argument points to an object that contains an invalid conversion
 159 state.
 160 .IP \fBEILSEQ\fR
 161 Invalid character sequence is detected.
 162 .SH ATTRIBUTES
 163 .LP
 164 See \fBattributes\fR(5) for descriptions of the following attributes:
 165 .TS
 166 box;
 167 c | c
 168 l | l .
 169 ATTRIBUTE TYPE  ATTRIBUTE VALUE
 170 _
 171 Interface Stability     See below.
 172 _
 173 MT-Level        See below.
 174 .TE
 175 
 176 .LP
 177 The
 178 .B mbrtowc()
 179 function is Standard.  The
 180 .B mbrtowc_l()
 181 function is Uncommitted.
 182 .LP
 183 If
 184 .I ps
 185 is a null pointer, these functions are Unsafe for use in
 186 multithreaded applications.  Otherwise they are MT-Safe.
 187 .SH SEE ALSO
 188 .LP
 189 .BR mbsinit (3C),
 190 .BR newlocale (3C),
 191 .BR setlocale (3C),
 192 .BR uselocale (3C),
 193 .BR attributes (5),
 194 .BR environ (5),
 195 .BR standards (5)