1.\" $NetBSD: wcrtomb.3,v 1.9 2007/02/20 08:33:25 wiz Exp $ 2.\" 3.\" Copyright (c)2002 Citrus Project, 4.\" All rights reserved. 5.\" 6.\" Redistribution and use in source and binary forms, with or without 7.\" modification, are permitted provided that the following conditions 8.\" are met: 9.\" 1. Redistributions of source code must retain the above copyright 10.\" notice, this list of conditions and the following disclaimer. 11.\" 2. Redistributions in binary form must reproduce the above copyright 12.\" notice, this list of conditions and the following disclaimer in the 13.\" documentation and/or other materials provided with the distribution. 14.\" 15.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25.\" SUCH DAMAGE. 26.\" 27.Dd February 4, 2002 28.Dt WCRTOMB 3 29.Os 30.\" ---------------------------------------------------------------------- 31.Sh NAME 32.Nm wcrtomb 33.Nd converts a wide character to a multibyte character (restartable) 34.\" ---------------------------------------------------------------------- 35.Sh LIBRARY 36.Lb libc 37.\" ---------------------------------------------------------------------- 38.Sh SYNOPSIS 39.In wchar.h 40.Ft size_t 41.Fn wcrtomb "char * restrict s" "wchar_t wc" "mbstate_t * restrict ps" 42.\" ---------------------------------------------------------------------- 43.Sh DESCRIPTION 44.Fn wcrtomb 45converts the wide character given by 46.Fa wc 47to the corresponding multibyte character, and stores it in the array 48pointed to by 49.Fa s 50unless 51.Fa s 52is a null pointer. 53This function will modify the first at most 54.Dv MB_CUR_MAX 55bytes of the array pointed to by 56.Fa s . 57.Pp 58The behaviour of 59.Fn wcrtomb 60is affected by the 61.Dv LC_CTYPE 62category of the current locale. 63.Pp 64These are the special cases: 65.Bl -tag -width 012345678901 66.It "wc == 0" 67For state-dependent encodings, 68.Fn wcrtomb 69stores a nul byte preceded by special byte sequence (if any) 70to return to an initial state in the array pointed to by 71.Fa s , 72and the state object pointed to by 73.Fa ps 74also returns to an initial state. 75.It "s == NULL" 76.Fn wcrtomb 77just places 78.Fa ps 79into an initial state. 80It is equivalent to the following call: 81.Bd -literal -offset indent 82wcrtomb(buf, L'\\0', ps); 83.Ed 84.Pp 85Here, 86.Fa buf 87is a dummy buffer. 88In this case, 89.Fa wc 90is ignored. 91.It "ps == NULL" 92.Fn mbrtowc 93uses its own internal state object to keep the conversion state, 94instead of 95.Fa ps 96mentioned in this manual page. 97.Pp 98Calling any other functions in 99.Lb libc 100never changes the internal 101state of 102.Fn mbrtowc , 103which is initialized at startup time of the program. 104.El 105.\" ---------------------------------------------------------------------- 106.Sh RETURN VALUES 107.Fn wcrtomb 108returns: 109.Bl -tag -width 012345678901 110.It "positive" 111The number of bytes (including any shift sequences) 112which are stored in the array. 113.It "(size_t)-1" 114.Fa wc 115is not a valid wide character. 116In this case, 117.Fn wcrtomb 118also sets 119.Va errno 120to indicate the error. 121.El 122.\" ---------------------------------------------------------------------- 123.Sh ERRORS 124.Fn wcrtomb 125may cause an error in the following case: 126.Bl -tag -width Er 127.It Bq Er EILSEQ 128.Fa wc 129is not a valid wide character. 130.It Bq Er EINVAL 131.Fa ps 132points to an invalid or uninitialized mbstate_t object. 133.El 134.\" ---------------------------------------------------------------------- 135.Sh SEE ALSO 136.Xr setlocale 3 , 137.Xr wctomb 3 138.\" ---------------------------------------------------------------------- 139.Sh STANDARDS 140The 141.Fn wcrtomb 142function conforms to 143.St -isoC-amd1 . 144The restrict qualifier is added at 145.St -isoC-99 . 146