1*50c77c6eSEd Schouten /*- 2*50c77c6eSEd Schouten * Copyright (c) 2013 Ed Schouten <ed@FreeBSD.org> 3*50c77c6eSEd Schouten * All rights reserved. 4*50c77c6eSEd Schouten * 5*50c77c6eSEd Schouten * Redistribution and use in source and binary forms, with or without 6*50c77c6eSEd Schouten * modification, are permitted provided that the following conditions 7*50c77c6eSEd Schouten * are met: 8*50c77c6eSEd Schouten * 1. Redistributions of source code must retain the above copyright 9*50c77c6eSEd Schouten * notice, this list of conditions and the following disclaimer. 10*50c77c6eSEd Schouten * 2. Redistributions in binary form must reproduce the above copyright 11*50c77c6eSEd Schouten * notice, this list of conditions and the following disclaimer in the 12*50c77c6eSEd Schouten * documentation and/or other materials provided with the distribution. 13*50c77c6eSEd Schouten * 14*50c77c6eSEd Schouten * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15*50c77c6eSEd Schouten * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16*50c77c6eSEd Schouten * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17*50c77c6eSEd Schouten * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18*50c77c6eSEd Schouten * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19*50c77c6eSEd Schouten * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20*50c77c6eSEd Schouten * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21*50c77c6eSEd Schouten * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22*50c77c6eSEd Schouten * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23*50c77c6eSEd Schouten * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24*50c77c6eSEd Schouten * SUCH DAMAGE. 25*50c77c6eSEd Schouten */ 26*50c77c6eSEd Schouten 27*50c77c6eSEd Schouten #include <sys/cdefs.h> 28*50c77c6eSEd Schouten __FBSDID("$FreeBSD$"); 29*50c77c6eSEd Schouten 30*50c77c6eSEd Schouten #include <uchar.h> 31*50c77c6eSEd Schouten #include <wchar.h> 32*50c77c6eSEd Schouten #include "xlocale_private.h" 33*50c77c6eSEd Schouten 34*50c77c6eSEd Schouten size_t 35*50c77c6eSEd Schouten mbrtoc32_l(char32_t * __restrict pc32, const char * __restrict s, size_t n, 36*50c77c6eSEd Schouten mbstate_t * __restrict ps, locale_t locale) 37*50c77c6eSEd Schouten { 38*50c77c6eSEd Schouten 39*50c77c6eSEd Schouten FIX_LOCALE(locale); 40*50c77c6eSEd Schouten if (ps == NULL) 41*50c77c6eSEd Schouten ps = &locale->mbrtoc32; 42*50c77c6eSEd Schouten 43*50c77c6eSEd Schouten /* Assume wchar_t uses UTF-32. */ 44*50c77c6eSEd Schouten return (mbrtowc_l(pc32, s, n, ps, locale)); 45*50c77c6eSEd Schouten } 46*50c77c6eSEd Schouten 47*50c77c6eSEd Schouten size_t 48*50c77c6eSEd Schouten mbrtoc32(char32_t * __restrict pc32, const char * __restrict s, size_t n, 49*50c77c6eSEd Schouten mbstate_t * __restrict ps) 50*50c77c6eSEd Schouten { 51*50c77c6eSEd Schouten 52*50c77c6eSEd Schouten return (mbrtoc32_l(pc32, s, n, ps, __get_locale())); 53*50c77c6eSEd Schouten } 54