wcstombs.c revision 227753
155682Smarkm/*- 2178825Sdfr * Copyright (c) 2002-2004 Tim J. Robbins. 355682Smarkm * All rights reserved. 455682Smarkm * 555682Smarkm * Copyright (c) 2011 The FreeBSD Foundation 655682Smarkm * All rights reserved. 755682Smarkm * Portions of this software were developed by David Chisnall 855682Smarkm * under sponsorship from the FreeBSD Foundation. 955682Smarkm * 1055682Smarkm * Redistribution and use in source and binary forms, with or without 1155682Smarkm * modification, are permitted provided that the following conditions 1255682Smarkm * are met: 1355682Smarkm * 1. Redistributions of source code must retain the above copyright 1455682Smarkm * notice, this list of conditions and the following disclaimer. 1555682Smarkm * 2. Redistributions in binary form must reproduce the above copyright 1655682Smarkm * notice, this list of conditions and the following disclaimer in the 1755682Smarkm * documentation and/or other materials provided with the distribution. 1855682Smarkm * 1955682Smarkm * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 2055682Smarkm * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2155682Smarkm * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2255682Smarkm * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 2355682Smarkm * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2455682Smarkm * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2555682Smarkm * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2655682Smarkm * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2755682Smarkm * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2855682Smarkm * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2955682Smarkm * SUCH DAMAGE. 3055682Smarkm */ 3155682Smarkm 3255682Smarkm#include <sys/cdefs.h> 3355682Smarkm__FBSDID("$FreeBSD: head/lib/libc/locale/wcstombs.c 227753 2011-11-20 14:45:42Z theraven $"); 34178825Sdfr 3555682Smarkm#include <limits.h> 3655682Smarkm#include <stdlib.h> 3755682Smarkm#include <wchar.h> 38102644Snectar#include "mblocal.h" 39102644Snectar 40102644Snectarsize_t 4155682Smarkmwcstombs_l(char * __restrict s, const wchar_t * __restrict pwcs, size_t n, 42120945Snectar locale_t locale) 4355682Smarkm{ 44178825Sdfr static const mbstate_t initial; 4555682Smarkm mbstate_t mbs; 4655682Smarkm const wchar_t *pwcsp; 4755682Smarkm FIX_LOCALE(locale); 4855682Smarkm 4955682Smarkm mbs = initial; 5055682Smarkm pwcsp = pwcs; 5155682Smarkm return (XLOCALE_CTYPE(locale)->__wcsnrtombs(s, &pwcsp, SIZE_T_MAX, n, &mbs)); 5255682Smarkm} 5355682Smarkmsize_t 5455682Smarkmwcstombs(char * __restrict s, const wchar_t * __restrict pwcs, size_t n) 5555682Smarkm{ 5655682Smarkm return wcstombs_l(s, pwcs, n, __get_locale()); 5755682Smarkm} 5855682Smarkm 59178825Sdfr