150c77c6eSEd Schouten /*-
2*4d846d26SWarner Losh * SPDX-License-Identifier: BSD-2-Clause
3d915a14eSPedro F. Giffuni *
450c77c6eSEd Schouten * Copyright (c) 2013 Ed Schouten <ed@FreeBSD.org>
550c77c6eSEd Schouten * All rights reserved.
650c77c6eSEd Schouten *
750c77c6eSEd Schouten * Redistribution and use in source and binary forms, with or without
850c77c6eSEd Schouten * modification, are permitted provided that the following conditions
950c77c6eSEd Schouten * are met:
1050c77c6eSEd Schouten * 1. Redistributions of source code must retain the above copyright
1150c77c6eSEd Schouten * notice, this list of conditions and the following disclaimer.
1250c77c6eSEd Schouten * 2. Redistributions in binary form must reproduce the above copyright
1350c77c6eSEd Schouten * notice, this list of conditions and the following disclaimer in the
1450c77c6eSEd Schouten * documentation and/or other materials provided with the distribution.
1550c77c6eSEd Schouten *
1650c77c6eSEd Schouten * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1750c77c6eSEd Schouten * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1850c77c6eSEd Schouten * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1950c77c6eSEd Schouten * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
2050c77c6eSEd Schouten * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2150c77c6eSEd Schouten * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2250c77c6eSEd Schouten * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2350c77c6eSEd Schouten * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2450c77c6eSEd Schouten * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2550c77c6eSEd Schouten * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2650c77c6eSEd Schouten * SUCH DAMAGE.
2750c77c6eSEd Schouten */
2850c77c6eSEd Schouten
2950c77c6eSEd Schouten #include <uchar.h>
3050c77c6eSEd Schouten #include <wchar.h>
3198f3acfaSYuri Pankov #include "mblocal.h"
3250c77c6eSEd Schouten
3350c77c6eSEd Schouten size_t
mbrtoc32_l(char32_t * __restrict pc32,const char * __restrict s,size_t n,mbstate_t * __restrict ps,locale_t locale)3450c77c6eSEd Schouten mbrtoc32_l(char32_t * __restrict pc32, const char * __restrict s, size_t n,
3550c77c6eSEd Schouten mbstate_t * __restrict ps, locale_t locale)
3650c77c6eSEd Schouten {
3750c77c6eSEd Schouten
3850c77c6eSEd Schouten FIX_LOCALE(locale);
3950c77c6eSEd Schouten if (ps == NULL)
4098f3acfaSYuri Pankov ps = &(XLOCALE_CTYPE(locale)->mbrtoc32);
4150c77c6eSEd Schouten
4250c77c6eSEd Schouten /* Assume wchar_t uses UTF-32. */
4350c77c6eSEd Schouten return (mbrtowc_l(pc32, s, n, ps, locale));
4450c77c6eSEd Schouten }
4550c77c6eSEd Schouten
4650c77c6eSEd Schouten size_t
mbrtoc32(char32_t * __restrict pc32,const char * __restrict s,size_t n,mbstate_t * __restrict ps)4750c77c6eSEd Schouten mbrtoc32(char32_t * __restrict pc32, const char * __restrict s, size_t n,
4850c77c6eSEd Schouten mbstate_t * __restrict ps)
4950c77c6eSEd Schouten {
5050c77c6eSEd Schouten
5150c77c6eSEd Schouten return (mbrtoc32_l(pc32, s, n, ps, __get_locale()));
5250c77c6eSEd Schouten }
53