X-Git-Url: https://git.saurik.com/apple/libc.git/blobdiff_plain/9385eb3d10ebe5eb398c52040ec3dbfba9b0cdcf..15de9d6b4ab2de27ae24b13b7b6c4d55fffe4aef:/locale/FreeBSD/mbsrtowcs.c diff --git a/locale/FreeBSD/mbsrtowcs.c b/locale/FreeBSD/mbsrtowcs.c index afff52f..da8b1e4 100644 --- a/locale/FreeBSD/mbsrtowcs.c +++ b/locale/FreeBSD/mbsrtowcs.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2002 Tim J. Robbins. + * Copyright (c) 2002-2004 Tim J. Robbins. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -25,50 +25,29 @@ */ #include -__FBSDID("$FreeBSD: src/lib/libc/locale/mbsrtowcs.c,v 1.2 2002/09/06 11:23:45 tjr Exp $"); +__FBSDID("$FreeBSD: src/lib/libc/locale/mbsrtowcs.c,v 1.6 2004/07/21 10:54:57 tjr Exp $"); + +#include "xlocale_private.h" #include #include #include #include +#include "mblocal.h" size_t -mbsrtowcs(wchar_t * __restrict dst, const char ** __restrict src, size_t len, - mbstate_t * __restrict ps __unused) +mbsrtowcs_l(wchar_t * __restrict dst, const char ** __restrict src, size_t len, + mbstate_t * __restrict ps, locale_t loc) { - const char *s; - size_t nchr; - wchar_t wc; - int nb; - - s = *src; - nchr = 0; - - if (dst == NULL) { - for (;;) { - if ((nb = (int)mbrtowc(&wc, s, MB_CUR_MAX, NULL)) < 0) - /* Invalid sequence - mbrtowc() sets errno. */ - return ((size_t)-1); - else if (nb == 0) - return (nchr); - s += nb; - nchr++; - } - /*NOTREACHED*/ - } + NORMALIZE_LOCALE(loc); + if (ps == NULL) + ps = &loc->__mbs_mbsrtowcs; + return (loc->__lc_ctype->__mbsnrtowcs(dst, src, SIZE_T_MAX, len, ps, loc)); +} - while (len-- > 0) { - if ((nb = (int)mbrtowc(dst, s, MB_CUR_MAX, NULL)) < 0) { - *src = s; - return ((size_t)-1); - } else if (nb == 0) { - *src = NULL; - return (nchr); - } - s += nb; - nchr++; - dst++; - } - *src = s; - return (nchr); +size_t +mbsrtowcs(wchar_t * __restrict dst, const char ** __restrict src, size_t len, + mbstate_t * __restrict ps) +{ + return mbsrtowcs_l(dst, src, len, ps, __current_locale()); }