1102050Stjr/*-
2127944Stjr * 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: releng/10.3/lib/libc/locale/mbrlen.c 227753 2011-11-20 14:45:42Z theraven $");
34102050Stjr
35102050Stjr#include <wchar.h>
36129154Stjr#include "mblocal.h"
37102050Stjr
38102050Stjrsize_t
39227753Stheravenmbrlen_l(const char * __restrict s, size_t n, mbstate_t * __restrict ps, locale_t locale)
40102050Stjr{
41227753Stheraven	FIX_LOCALE(locale);
42127944Stjr	if (ps == NULL)
43227753Stheraven		ps = &locale->mbrlen;
44227753Stheraven	return (XLOCALE_CTYPE(locale)->__mbrtowc(NULL, s, n, ps));
45102050Stjr}
46227753Stheraven
47227753Stheravensize_t
48227753Stheravenmbrlen(const char * __restrict s, size_t n, mbstate_t * __restrict ps)
49227753Stheraven{
50227753Stheraven	return mbrlen_l(s, n, ps, __get_locale());
51227753Stheraven}
52