From 49c4407313ace0d3a0237f6953d3eb74922a0ea6 Mon Sep 17 00:00:00 2001 From: Baptiste Daroussin Date: Thu, 21 Apr 2016 07:36:11 +0000 Subject: [PATCH] Restore the original ascii.c from prior to r290494 It was doing the right thing, there was no need to "fail" to reinvent it from none.c Pointy hat: bapt Submitted by: ache --- lib/libc/locale/ascii.c | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/lib/libc/locale/ascii.c b/lib/libc/locale/ascii.c index a550c70deb69..784814d2664d 100644 --- a/lib/libc/locale/ascii.c +++ b/lib/libc/locale/ascii.c @@ -1,6 +1,4 @@ -/* - * Copyright 2013 Garrett D'Amore - * Copyright 2010 Nexenta Systems, Inc. All rights reserved. +/*- * Copyright (c) 2002-2004 Tim J. Robbins. All rights reserved. * Copyright (c) 1993 * The Regents of the University of California. All rights reserved. @@ -36,8 +34,6 @@ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. - * - * @(#)none.c 8.1 (Berkeley) 6/4/93 */ #include @@ -65,7 +61,7 @@ static size_t _ascii_wcsnrtombs(char * __restrict, const wchar_t ** __restrict, size_t, size_t, mbstate_t * __restrict); int -_ascii_init(struct xlocale_ctype *l, _RuneLocale *rl) +_ascii_init(struct xlocale_ctype *l,_RuneLocale *rl) { l->__mbrtowc = _ascii_mbrtowc; @@ -82,6 +78,7 @@ _ascii_init(struct xlocale_ctype *l, _RuneLocale *rl) static int _ascii_mbsinit(const mbstate_t *ps __unused) { + /* * Encoding is not state dependent - we are always in the * initial state. @@ -93,6 +90,7 @@ static size_t _ascii_mbrtowc(wchar_t * __restrict pwc, const char * __restrict s, size_t n, mbstate_t * __restrict ps __unused) { + if (s == NULL) /* Reset to initial shift state (no-op) */ return (0); @@ -132,13 +130,11 @@ _ascii_mbsnrtowcs(wchar_t * __restrict dst, const char ** __restrict src, size_t nchr; if (dst == NULL) { - s = memchr(*src, '\0', nms); - if (s == NULL) - return (nms); - - if (*s & 0x80) { - errno = EILSEQ; - return ((size_t)-1); + for (s = *src; nms > 0 && *s != '\0'; s++, nms--) { + if (*s & 0x80) { + errno = EILSEQ; + return ((size_t)-1); + } } return (s - *src); } @@ -193,3 +189,4 @@ _ascii_wcsnrtombs(char * __restrict dst, const wchar_t ** __restrict src, *src = s; return (nchr); } +