1*64d4e987Stedu.\" $OpenBSD: wcsrtombs.3,v 1.5 2013/06/05 03:39:22 tedu Exp $ 2561d433dSespie.\" $NetBSD: wcsrtombs.3,v 1.6 2003/09/08 17:54:32 wiz Exp $ 3561d433dSespie.\" 4561d433dSespie.\" Copyright (c)2002 Citrus Project, 5561d433dSespie.\" All rights reserved. 6561d433dSespie.\" 7561d433dSespie.\" Redistribution and use in source and binary forms, with or without 8561d433dSespie.\" modification, are permitted provided that the following conditions 9561d433dSespie.\" are met: 10561d433dSespie.\" 1. Redistributions of source code must retain the above copyright 11561d433dSespie.\" notice, this list of conditions and the following disclaimer. 12561d433dSespie.\" 2. Redistributions in binary form must reproduce the above copyright 13561d433dSespie.\" notice, this list of conditions and the following disclaimer in the 14561d433dSespie.\" documentation and/or other materials provided with the distribution. 15561d433dSespie.\" 16561d433dSespie.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17561d433dSespie.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18561d433dSespie.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19561d433dSespie.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20561d433dSespie.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21561d433dSespie.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22561d433dSespie.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23561d433dSespie.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24561d433dSespie.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25561d433dSespie.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26561d433dSespie.\" SUCH DAMAGE. 27561d433dSespie.\" 28*64d4e987Stedu.Dd $Mdocdate: June 5 2013 $ 29561d433dSespie.Dt WCSRTOMBS 3 30561d433dSespie.Os 31561d433dSespie.\" ---------------------------------------------------------------------- 32561d433dSespie.Sh NAME 33a814a5ffSmatthew.Nm wcsrtombs , 34a814a5ffSmatthew.Nm wcsnrtombs 35fbad59fbSjmc.Nd converts a wide-character string to a multibyte character string \ 36561d433dSespie(restartable) 37561d433dSespie.\" ---------------------------------------------------------------------- 38561d433dSespie.Sh SYNOPSIS 39*64d4e987Stedu.In wchar.h 40561d433dSespie.Ft size_t 41a814a5ffSmatthew.Fn wcsrtombs "const char * restrict dst" "const wchar_t ** restrict src" \ 42a814a5ffSmatthew"size_t len" "mbstate_t * restrict ps" 43a814a5ffSmatthew.Ft size_t 44a814a5ffSmatthew.Fn wcsnrtombs "const char * restrict dst" "const wchar_t ** restrict src" \ 45a814a5ffSmatthew"size_t nwc" "size_t len" "mbstate_t * restrict ps" 46561d433dSespie.\" ---------------------------------------------------------------------- 47561d433dSespie.Sh DESCRIPTION 48561d433dSespieThe 49561d433dSespie.Fn wcsrtombs 50a814a5ffSmatthewfunction converts the wide-character string indirectly pointed to by 51a814a5ffSmatthew.Fa src 52a814a5ffSmatthewto the corresponding multibyte character string 53a814a5ffSmatthewand stores it to the array pointed to by 54a814a5ffSmatthew.Fa dst . 55561d433dSespieThe conversion stops due to the following reasons: 56561d433dSespie.Bl -bullet 57561d433dSespie.It 58561d433dSespieThe conversion reaches a null wide character. 59561d433dSespieIn this case, the null wide character is also converted. 60561d433dSespie.It 61a814a5ffSmatthewThe conversion has already stored 62a814a5ffSmatthew.Fa len 63561d433dSespiebytes to the array pointed to by 64a814a5ffSmatthew.Fa dst . 65561d433dSespie.It 66561d433dSespieThe conversion encounters an invalid character. 67561d433dSespie.El 68561d433dSespie.Pp 69a814a5ffSmatthewThe 70a814a5ffSmatthew.Fn wcsnrtombs 71a814a5ffSmatthewfunction is equivalent to 72a814a5ffSmatthew.Fn wcsrtombs 73a814a5ffSmatthewexcept that it additionally stops the conversion after processing 74a814a5ffSmatthew.Fa nwc 75a814a5ffSmatthewwide characters. 76a814a5ffSmatthew.Pp 77a814a5ffSmatthewEach character will be converted as if 78561d433dSespie.Xr wcrtomb 3 79561d433dSespieis continuously called, except the internal state of 80561d433dSespie.Xr wcrtomb 3 81561d433dSespiewill not be affected. 82561d433dSespie.Pp 83561d433dSespieAfter conversion, 84561d433dSespieif 85a814a5ffSmatthew.Fa dst 86a814a5ffSmatthewis not a null pointer, 87561d433dSespiethe pointer object pointed to by 88a814a5ffSmatthew.Fa src 89a814a5ffSmatthewis a null pointer (if the conversion is stopped due to reaching a null wide character) 90a814a5ffSmatthewor the address just past the last wide character processed. 91561d433dSespie.Pp 92561d433dSespieIf 93a814a5ffSmatthew.Fa dst 94561d433dSespieis not a null pointer and the conversion is stopped due to reaching 95a814a5ffSmatthewa null wide character, 96a814a5ffSmatthewthe state object pointed to by 97561d433dSespie.Fa ps 98a814a5ffSmatthewis set to an initial state after the conversion has taken place. 99561d433dSespie.Pp 100561d433dSespieThe behaviour of the 101561d433dSespie.Fn wcsrtombs 102a814a5ffSmatthewand 103a814a5ffSmatthew.Fn wcsnrtombs 104a814a5ffSmatthewfunctions is affected by the 105561d433dSespie.Dv LC_CTYPE 106561d433dSespiecategory of the current locale. 107561d433dSespie.Pp 108a814a5ffSmatthewThere are two special cases: 109561d433dSespie.Bl -tag -width 012345678901 110a814a5ffSmatthew.It "dst == NULL" 111a814a5ffSmatthewThe conversion takes place, but the resulting multibyte string is discarded. 112a814a5ffSmatthewIn this case, the pointer object pointed to by 113a814a5ffSmatthew.Fa src 114a814a5ffSmatthewis not modified and 115a814a5ffSmatthew.Fa len 116561d433dSespieis ignored. 117561d433dSespie.It "ps == NULL" 118a814a5ffSmatthewThe 119561d433dSespie.Fn wcsrtombs 120a814a5ffSmatthewand 121a814a5ffSmatthew.Fn wcsnrtombs 122a814a5ffSmatthewfunctions use their own internal state objects to keep the conversion state, 123561d433dSespieinstead of 124561d433dSespie.Fa ps 125a814a5ffSmatthewas mentioned in this manual page. 126561d433dSespie.Pp 127561d433dSespieCalling any other functions in 128561d433dSespie.Em libc 129a814a5ffSmatthewnever change these internal states, 130a814a5ffSmatthewwhich are initialized at startup time of the program. 131561d433dSespie.El 132561d433dSespie.\" ---------------------------------------------------------------------- 133561d433dSespie.Sh RETURN VALUES 134a814a5ffSmatthewThe 135561d433dSespie.Fn wcsrtombs 136a814a5ffSmatthewand 137a814a5ffSmatthew.Fn wcsnrtombs 138a814a5ffSmatthewfunctions return: 139561d433dSespie.Bl -tag -width 012345678901 140561d433dSespie.It 0 or positive 141561d433dSespieNumber of bytes stored to the array pointed to by 142a814a5ffSmatthew.Fa dst , 143561d433dSespieexcept for a null byte. 144561d433dSespieThere is no cases that the value returned is greater than 145a814a5ffSmatthew.Fa len 146561d433dSespie(unless 147a814a5ffSmatthew.Fa dst 148561d433dSespieis a null pointer). 149561d433dSespieIf the return value is equal to 150a814a5ffSmatthew.Fa len , 151561d433dSespiethe string pointed to by 152a814a5ffSmatthew.Fa dst 153561d433dSespiewill not be null-terminated. 154561d433dSespie.It (size_t)-1 155a814a5ffSmatthew.Fa src 156561d433dSespiepoints to the string containing invalid wide character. 157a814a5ffSmatthewIn this case, 158a814a5ffSmatthew.Va errno 159a814a5ffSmatthewis set to indicate the error. 160561d433dSespie.El 161561d433dSespie.\" ---------------------------------------------------------------------- 162561d433dSespie.Sh ERRORS 163a814a5ffSmatthewThe 164561d433dSespie.Fn wcsrtombs 165a814a5ffSmatthewand 166a814a5ffSmatthew.Fn wcsnrtombs 167a814a5ffSmatthewfunctions may return the following errors: 168561d433dSespie.Bl -tag -width Er 169561d433dSespie.It Bq Er EILSEQ 170a814a5ffSmatthew.Fa src 171561d433dSespiepoints to the string containing an invalid wide character. 172a814a5ffSmatthew.It Bq Er EINVAL 173a814a5ffSmatthew.Fa ps 174a814a5ffSmatthewpoints to an invalid or uninitialized mbstate_t object. 175561d433dSespie.El 176561d433dSespie.\" ---------------------------------------------------------------------- 177561d433dSespie.Sh SEE ALSO 178561d433dSespie.Xr setlocale 3 , 179561d433dSespie.Xr wcrtomb 3 , 180561d433dSespie.Xr wcstombs 3 181561d433dSespie.\" ---------------------------------------------------------------------- 182561d433dSespie.Sh STANDARDS 183561d433dSespieThe 184561d433dSespie.Fn wcsrtombs 185561d433dSespiefunction conforms to 186561d433dSespie.St -ansiC . 187561d433dSespieThe restrict qualifier is added at 188561d433dSespie.\" .St -isoC99 . 189561d433dSespieISO/IEC 9899/AMD1:1995 190561d433dSespie.Pq Dq ISO C99 . 191a814a5ffSmatthew.Pp 192a814a5ffSmatthewThe 193a814a5ffSmatthew.Fn wcsnrtombs 194a814a5ffSmatthewfunction conforms to 195a814a5ffSmatthew.St -p1003.1-2008 . 196