c32rtomb.c revision 250883
1250883Sed/*- 2250883Sed * Copyright (c) 2013 Ed Schouten <ed@FreeBSD.org> 3250883Sed * All rights reserved. 4250883Sed * 5250883Sed * Redistribution and use in source and binary forms, with or without 6250883Sed * modification, are permitted provided that the following conditions 7250883Sed * are met: 8250883Sed * 1. Redistributions of source code must retain the above copyright 9250883Sed * notice, this list of conditions and the following disclaimer. 10250883Sed * 2. Redistributions in binary form must reproduce the above copyright 11250883Sed * notice, this list of conditions and the following disclaimer in the 12250883Sed * documentation and/or other materials provided with the distribution. 13250883Sed * 14250883Sed * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15250883Sed * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16250883Sed * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17250883Sed * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18250883Sed * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19250883Sed * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20250883Sed * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21250883Sed * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22250883Sed * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23250883Sed * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24250883Sed * SUCH DAMAGE. 25250883Sed */ 26250883Sed 27250883Sed#include <sys/cdefs.h> 28250883Sed__FBSDID("$FreeBSD: head/lib/libc/locale/c32rtomb.c 250883 2013-05-21 19:59:37Z ed $"); 29250883Sed 30250883Sed#include <errno.h> 31250883Sed#include <uchar.h> 32250883Sed#include <wchar.h> 33250883Sed#include "xlocale_private.h" 34250883Sed 35250883Sedsize_t 36250883Sedc32rtomb_l(char * __restrict s, char32_t c32, mbstate_t * __restrict ps, 37250883Sed locale_t locale) 38250883Sed{ 39250883Sed 40250883Sed /* Unicode Standard 5.0, D90: ill-formed characters. */ 41250883Sed if ((c32 >= 0xd800 && c32 <= 0xdfff) || c32 > 0x10ffff) { 42250883Sed errno = EILSEQ; 43250883Sed return ((size_t)-1); 44250883Sed } 45250883Sed 46250883Sed FIX_LOCALE(locale); 47250883Sed if (ps == NULL) 48250883Sed ps = &locale->c32rtomb; 49250883Sed 50250883Sed /* Assume wchar_t uses UTF-32. */ 51250883Sed return (wcrtomb_l(s, c32, ps, locale)); 52250883Sed} 53250883Sed 54250883Sedsize_t 55250883Sedc32rtomb(char * __restrict s, char32_t c32, mbstate_t * __restrict ps) 56250883Sed{ 57250883Sed 58250883Sed return (c32rtomb_l(s, c32, ps, __get_locale())); 59250883Sed} 60