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 MBSRTOWCS 3C "Nov 1, 2003"
  11 .SH NAME
  12 mbsrtowcs, mbsrtowcs_l \- convert a character string to a wide-character string
  13 (restartable)
  14 .SH SYNOPSIS
  15 .LP
  16 .nf
  17 #include <wchar.h>
  18 
  19 \fBsize_t\fR \fBmbsrtowcs\fR(\fBwchar_t *restrict\fR \fIdst\fR, \fBconst char **restrict\fR \fIsrc\fR,
  20      \fBsize_t\fR \fIlen\fR, \fBmbstate_t *restrict\fR \fIps\fR);
  21 
  22 \fBsize_t\fR \fBmbsrtowcs_l\fR(\fBwchar_t *restrict\fR \fIdst\fR, \fBconst char **restrict\fR \fIsrc\fR,
  23      \fBsize_t\fR \fIlen\fR, \fBmbstate_t *restrict\fR \fIps\fR, \fBlocale_t\fR \fIloc\fR);
  24 .fi
  25 .LP
  26 .nf
  27 \fBsize_t\fR \fBmbsnrtowcs\fR(\fBwchar_t *restrict\fR \fIdst\fR, \fBconst char **restrict\fR \fIsrc\fR,
  28      \fBsize_t\fR \fInms\fR, \fBsize_t\fR \fIlen\fR, \fBmbstate_t *restrict\fR \fIps\fR);
  29 
  30 \fBsize_t\fR \fBmbsnrtowcs_l\fR(\fBwchar_t *restrict\fR \fIdst\fR, \fBconst char **restrict\fR \fIsrc\fR,
  31      \fBsize_t\fR \fInms\fR, \fBsize_t\fR \fIlen\fR, \fBmbstate_t *restrict\fR \fIps\fR,
  32      \fBlocale_t\fR \fIloc\fR);
  33 .fi
  34 
  35 
  36 .SH DESCRIPTION
  37 .sp
  38 .LP
  39 The \fBmbsrtowcs()\fR function converts a sequence of characters, beginning in
  40 the conversion state described by the object pointed to by \fIps\fR, from the
  41 array indirectly pointed to by \fIsrc\fR into a sequence of corresponding
  42 wide-characters. If \fIdst\fR is not a null pointer, the converted characters
  43 are stored into the array pointed to by  \fIdst\fR. Conversion continues up to
  44 and including a terminating null character, which is also stored.  Conversion
  45 stops early in either of the following cases:
  46 .RS +4
  47 .TP
  48 .ie t \(bu
  49 .el o
  50 When a sequence of bytes is encountered that does not form a valid character.
  51 .RE
  52 .RS +4
  53 .TP
  54 .ie t \(bu
  55 .el o
  56 When \fIlen\fR codes have been stored into the array pointed to by \fIdst\fR
  57 (and  \fIdst\fR is not a null pointer).
  58 .RE
  59 .sp
  60 .LP
  61 Each conversion takes place as if by a call to the \fBmbrtowc()\fR function.
  62 .sp
  63 .LP
  64 If \fIdst\fR is not a null pointer, the pointer object pointed to by \fIsrc\fR
  65 is assigned either a null pointer (if conversion stopped due to reaching a
  66 terminating null character) or the address just past the last character
  67 converted (if any).  If conversion stopped due to reaching a terminating null
  68 character, and if \fIdst\fR is not a null pointer, the resulting state
  69 described is the initial conversion state.
  70 .sp
  71 .LP
  72 If \fIps\fR is a null pointer, the \fBmbsrtowcs()\fR function uses its own
  73 internal \fBmbstate_t\fR object, which is initialized at program startup to the
  74 initial conversion state.  Otherwise, the  \fBmbstate_t\fR object pointed to by
  75 \fIps\fR is used to completely describe the current conversion state of the
  76 associated character sequence. illumos will behave as if no function defined in
  77 the illumos Reference Manual calls \fBmbsrtowcs()\fR.
  78 .sp
  79 .LP
  80 The function \fBmbsnrtowcs\fR function behaves identically to \fBmbsrtowcs\fR,
  81 except the conversion stops after reading \fInms\fR bytes from the
  82 buffer pointed to by \fIsrc\fR.
  83 .sp
  84 .LP
  85 The behavior of this function is affected by the \fBLC_CTYPE\fR category of the
  86 current locale.  See \fBenviron\fR(5). The functions \fBmbsrtowcs_l()\fR and
  87 \fBmbsnrtowcs_l()\fR behaves identically to \fBmbsrtowcs()\fR and
  88 \fBmbsnrtowcs()\fR, except that instead of using the current locale, it uses the
  89 locale specified by \fIloc\fR.
  90 .SH RETURN VALUES
  91 .sp
  92 .LP
  93 If the input conversion encounters a sequence of bytes that do not form a valid
  94 character, an encoding error occurs.  In this case, the \fBmbsrtowcs()\fR
  95 function stores the value of the macro \fBEILSEQ\fR in \fBerrno\fR and returns
  96 \fB(size_t)\(mi1\fR; the conversion state is undefined.  Otherwise, it returns
  97 the number of characters successfully converted, not including the terminating
  98 null (if any).
  99 .SH ERRORS
 100 .sp
 101 .LP
 102 The \fBmbsrtowcs()\fR function may fail if:
 103 .sp
 104 .ne 2
 105 .na
 106 \fB\fBEINVAL\fR\fR
 107 .ad
 108 .RS 10n
 109 The \fIps\fR argument points to an object that contains an invalid conversion
 110 state.
 111 .RE
 112 
 113 .sp
 114 .ne 2
 115 .na
 116 \fB\fBEILSEQ\fR\fR
 117 .ad
 118 .RS 10n
 119 Invalid character sequence is detected.
 120 .RE
 121 
 122 .SH ATTRIBUTES
 123 .sp
 124 .LP
 125 See \fBattributes\fR(5) for descriptions of the following attributes:
 126 .sp
 127 
 128 .sp
 129 .TS
 130 box;
 131 c | c
 132 l | l .
 133 ATTRIBUTE TYPE  ATTRIBUTE VALUE
 134 _
 135 Interface Stability     Standard
 136 _
 137 MT-Level        See NOTES below
 138 .TE
 139 
 140 .SH SEE ALSO
 141 .sp
 142 .LP
 143 \fBmbrtowc\fR(3C), \fBmbsinit\fR(3C), \fBsetlocale\fR(3C), \fBuselocale()\fR, \fBattributes\fR(5),
 144 \fBenviron\fR(5), \fBstandards\fR(5)
 145 .SH NOTES
 146 .sp
 147 .LP
 148 If \fIps\fR is not a null pointer, \fBmbsrtowcs()\fR uses the \fBmbstate_t\fR
 149 object pointed to by \fIps\fR and the function can be used safely in
 150 multithreaded applications, as long as \fBsetlocale\fR(3C) is not being called
 151 to change the locale or a per-thread locale has been installed with
 152 \fBuselocale()\fR. If \fIps\fR is a null pointer, \fBmbsrtowcs()\fR uses its
 153 internal \fBmbstate_t\fR object and the function is Unsafe in multithreaded
 154 applications.