mbstowcs.c revision 330897
1112102Ssam/*- 2112102Ssam * SPDX-License-Identifier: BSD-2-Clause-FreeBSD 3112102Ssam * 4112102Ssam * Copyright (c) 2002-2004 Tim J. Robbins. 5112102Ssam * All rights reserved. 6112102Ssam * 7112102Ssam * Copyright (c) 2011 The FreeBSD Foundation 8112102Ssam * All rights reserved. 9112102Ssam * Portions of this software were developed by David Chisnall 10112102Ssam * under sponsorship from the FreeBSD Foundation. 11112102Ssam * 12112102Ssam * Redistribution and use in source and binary forms, with or without 13112102Ssam * modification, are permitted provided that the following conditions 14112102Ssam * are met: 15112102Ssam * 1. Redistributions of source code must retain the above copyright 16112102Ssam * notice, this list of conditions and the following disclaimer. 17112102Ssam * 2. Redistributions in binary form must reproduce the above copyright 18112102Ssam * notice, this list of conditions and the following disclaimer in the 19112102Ssam * documentation and/or other materials provided with the distribution. 20112102Ssam * 21112102Ssam * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 22112102Ssam * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23112102Ssam * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24112102Ssam * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 25112102Ssam * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26112102Ssam * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27112102Ssam * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28112102Ssam * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29112102Ssam * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30112102Ssam * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31112102Ssam * SUCH DAMAGE. 32112102Ssam */ 33112102Ssam 34112102Ssam#include <sys/cdefs.h> 35115392Sru__FBSDID("$FreeBSD: stable/11/lib/libc/locale/mbstowcs.c 330897 2018-03-14 03:19:51Z eadler $"); 36112102Ssam 37112102Ssam#include <limits.h> 38112102Ssam#include <stdlib.h> 39115392Sru#include <wchar.h> 40115392Sru#include "mblocal.h" 41115392Sru 42112102Ssamsize_t 43112102Ssammbstowcs_l(wchar_t * __restrict pwcs, const char * __restrict s, size_t n, locale_t locale) 44112102Ssam{ 45112102Ssam static const mbstate_t initial; 46112102Ssam mbstate_t mbs; 47112102Ssam const char *sp; 48115392Sru FIX_LOCALE(locale); 49115392Sru 50112102Ssam mbs = initial; 51112102Ssam sp = s; 52112102Ssam return (XLOCALE_CTYPE(locale)->__mbsnrtowcs(pwcs, &sp, SIZE_T_MAX, n, &mbs)); 53112102Ssam} 54112102Ssamsize_t 55112102Ssammbstowcs(wchar_t * __restrict pwcs, const char * __restrict s, size_t n) 56123901Sbrueffer{ 57112102Ssam return mbstowcs_l(pwcs, s, n, __get_locale()); 58112102Ssam} 59112102Ssam