1102050Stjr/*-
2127835Stjr * Copyright (c) 2002-2004 Tim J. Robbins.
3102050Stjr * All rights reserved.
4102050Stjr *
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 *
10102050Stjr * Redistribution and use in source and binary forms, with or without
11102050Stjr * modification, are permitted provided that the following conditions
12102050Stjr * are met:
13102050Stjr * 1. Redistributions of source code must retain the above copyright
14102050Stjr *    notice, this list of conditions and the following disclaimer.
15102050Stjr * 2. Redistributions in binary form must reproduce the above copyright
16102050Stjr *    notice, this list of conditions and the following disclaimer in the
17102050Stjr *    documentation and/or other materials provided with the distribution.
18102050Stjr *
19102050Stjr * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20102050Stjr * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21102050Stjr * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22102050Stjr * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
23102050Stjr * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24102050Stjr * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25102050Stjr * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26102050Stjr * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27102050Stjr * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28102050Stjr * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29102050Stjr * SUCH DAMAGE.
30102050Stjr */
31102050Stjr
32102050Stjr#include <sys/cdefs.h>
33102050Stjr__FBSDID("$FreeBSD$");
34102050Stjr
35102050Stjr#include <wchar.h>
36129153Stjr#include "mblocal.h"
37102050Stjr
38102050Stjrsize_t
39227753Stheravenmbrtowc_l(wchar_t * __restrict pwc, const char * __restrict s,
40227753Stheraven    size_t n, mbstate_t * __restrict ps, locale_t locale)
41227753Stheraven{
42227753Stheraven	FIX_LOCALE(locale);
43227753Stheraven	if (ps == NULL)
44227753Stheraven		ps = &locale->mbrtowc;
45227753Stheraven	return (XLOCALE_CTYPE(locale)->__mbrtowc(pwc, s, n, ps));
46227753Stheraven}
47227753Stheraven
48227753Stheravensize_t
49121845Stjrmbrtowc(wchar_t * __restrict pwc, const char * __restrict s,
50121845Stjr    size_t n, mbstate_t * __restrict ps)
51102050Stjr{
52227753Stheraven	return mbrtowc_l(pwc, s, n, ps, __get_locale());
53121845Stjr}
54