1102697Stjr/*- 2127944Stjr * Copyright (c) 2002-2004 Tim J. Robbins. 3118593Stjr * All rights reserved. 4102697Stjr * 5227753Stheraven * Copyright (c) 2011 The FreeBSD Foundation 6227753Stheraven * All rights reserved. 7227753Stheraven * Portions of this software were developed by David Chisnall 8227753Stheraven * under sponsorship from the FreeBSD Foundation. 9227753Stheraven * 10102697Stjr * Redistribution and use in source and binary forms, with or without 11102697Stjr * modification, are permitted provided that the following conditions 12102697Stjr * are met: 13102697Stjr * 1. Redistributions of source code must retain the above copyright 14102697Stjr * notice, this list of conditions and the following disclaimer. 15102697Stjr * 2. Redistributions in binary form must reproduce the above copyright 16102697Stjr * notice, this list of conditions and the following disclaimer in the 17102697Stjr * documentation and/or other materials provided with the distribution. 18102697Stjr * 19118593Stjr * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 20102697Stjr * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21102697Stjr * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22118593Stjr * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 23102697Stjr * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24102697Stjr * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25102697Stjr * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26102697Stjr * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27102697Stjr * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28102697Stjr * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29102697Stjr * SUCH DAMAGE. 30102697Stjr */ 31102697Stjr 32102697Stjr#include <sys/cdefs.h> 33102697Stjr__FBSDID("$FreeBSD$"); 34102697Stjr 35132497Stjr#include <limits.h> 36102697Stjr#include <stdlib.h> 37118593Stjr#include <wchar.h> 38129179Stjr#include "mblocal.h" 39102697Stjr 40102697Stjrsize_t 41227753Stheravenmbstowcs_l(wchar_t * __restrict pwcs, const char * __restrict s, size_t n, locale_t locale) 42102697Stjr{ 43127986Stjr static const mbstate_t initial; 44127986Stjr mbstate_t mbs; 45187302Srdivacky const char *sp; 46227753Stheraven FIX_LOCALE(locale); 47102697Stjr 48127986Stjr mbs = initial; 49187302Srdivacky sp = s; 50227753Stheraven return (XLOCALE_CTYPE(locale)->__mbsnrtowcs(pwcs, &sp, SIZE_T_MAX, n, &mbs)); 51102697Stjr} 52227753Stheravensize_t 53227753Stheravenmbstowcs(wchar_t * __restrict pwcs, const char * __restrict s, size_t n) 54227753Stheraven{ 55227753Stheraven return mbstowcs_l(pwcs, s, n, __get_locale()); 56227753Stheraven} 57