4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync/*
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync * Copyright 2013 Garrett D'Amore <garrett@damore.org>
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync * Copyright 2010 Nexenta Systems, Inc. All rights reserved.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync * Copyright (c) 2002, 2003 Tim J. Robbins.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync * All rights reserved.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync *
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync * Redistribution and use in source and binary forms, with or without
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync * modification, are permitted provided that the following conditions
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync * are met:
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync * 1. Redistributions of source code must retain the above copyright
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync * notice, this list of conditions and the following disclaimer.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync * 2. Redistributions in binary form must reproduce the above copyright
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync * notice, this list of conditions and the following disclaimer in the
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync * documentation and/or other materials provided with the distribution.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync *
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync * SUCH DAMAGE.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync */
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync#include "lint.h"
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync#include <stdio.h>
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync#include <wchar.h>
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync#include <locale.h>
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync#include <xlocale.h>
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync#include "mblocal.h"
wint_t
btowc_l(int c, locale_t loc)
{
static const mbstate_t initial = { 0 };
mbstate_t mbs = initial;
char cc;
wchar_t wc;
if (c == EOF)
return (WEOF);
/*
* We expect mbrtowc() to return 0 or 1, hence the check for n > 1
* which detects error return values as well as "impossible" byte
* counts.
*/
cc = (char)c;
if (mbrtowc_l(&wc, &cc, 1, &mbs, loc) > 1)
return (WEOF);
return (wc);
}
wint_t
btowc(int c)
{
return (btowc_l(c, uselocale(NULL)));
}