X-Git-Url: https://git.saurik.com/apple/libc.git/blobdiff_plain/9385eb3d10ebe5eb398c52040ec3dbfba9b0cdcf..15de9d6b4ab2de27ae24b13b7b6c4d55fffe4aef:/locale/FreeBSD/btowc.c?ds=sidebyside diff --git a/locale/FreeBSD/btowc.c b/locale/FreeBSD/btowc.c index 4b5964b..38122e7 100644 --- a/locale/FreeBSD/btowc.c +++ b/locale/FreeBSD/btowc.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2002 Tim J. Robbins. + * Copyright (c) 2002, 2003 Tim J. Robbins. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -25,21 +25,38 @@ */ #include -__FBSDID("$FreeBSD: src/lib/libc/locale/btowc.c,v 1.1 2002/08/03 13:49:55 tjr Exp $"); +__FBSDID("$FreeBSD: src/lib/libc/locale/btowc.c,v 1.4 2004/05/12 14:26:54 tjr Exp $"); -#include +#include "xlocale_private.h" + +#include #include +#include "mblocal.h" wint_t -btowc(int c) +btowc_l(int c, locale_t loc) { - rune_t r; + static const mbstate_t initial; + mbstate_t mbs = initial; char cc; + wchar_t wc; + NORMALIZE_LOCALE(loc); 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 ((r = sgetrune(&cc, 1, NULL)) == _INVALID_RUNE) + if (loc->__lc_ctype->__mbrtowc(&wc, &cc, 1, &mbs, loc) > 1) return (WEOF); - return (r); + return (wc); +} + +wint_t +btowc(int c) +{ + return btowc_l(c, __current_locale()); }