1101267Stjr/*- 2127944Stjr * Copyright (c) 2002-2004 Tim J. Robbins. 3101267Stjr * All rights reserved. 4101267Stjr * 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 * 10101267Stjr * Redistribution and use in source and binary forms, with or without 11101267Stjr * modification, are permitted provided that the following conditions 12101267Stjr * are met: 13101267Stjr * 1. Redistributions of source code must retain the above copyright 14101267Stjr * notice, this list of conditions and the following disclaimer. 15101267Stjr * 2. Redistributions in binary form must reproduce the above copyright 16101267Stjr * notice, this list of conditions and the following disclaimer in the 17101267Stjr * documentation and/or other materials provided with the distribution. 18101267Stjr * 19101267Stjr * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 20101267Stjr * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21101267Stjr * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22101267Stjr * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 23101267Stjr * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24101267Stjr * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25101267Stjr * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26101267Stjr * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27101267Stjr * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28101267Stjr * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29101267Stjr * SUCH DAMAGE. 30101267Stjr */ 31101267Stjr 32101267Stjr#include <sys/cdefs.h> 33101267Stjr__FBSDID("$FreeBSD$"); 34101267Stjr 35118589Stjr#include <limits.h> 36118589Stjr#include <stdio.h> 37101267Stjr#include <wchar.h> 38129154Stjr#include "mblocal.h" 39101267Stjr 40101267Stjrint 41227753Stheravenwctob_l(wint_t c, locale_t locale) 42101267Stjr{ 43127944Stjr static const mbstate_t initial; 44127944Stjr mbstate_t mbs = initial; 45118589Stjr char buf[MB_LEN_MAX]; 46227753Stheraven FIX_LOCALE(locale); 47101267Stjr 48227753Stheraven if (c == WEOF || XLOCALE_CTYPE(locale)->__wcrtomb(buf, c, &mbs) != 1) 49101267Stjr return (EOF); 50118589Stjr return ((unsigned char)*buf); 51101267Stjr} 52227753Stheravenint 53227753Stheravenwctob(wint_t c) 54227753Stheraven{ 55227753Stheraven return wctob_l(c, __get_locale()); 56227753Stheraven} 57