Author: bapt
Date: Thu Apr 21 06:27:06 2016
New Revision: 298395
URL: https://svnweb.freebsd.org/changeset/base/298395

Log:
  Restore histrory messed up in r290620
  
  ascii.c was removed during r290494 but this introduced an issue with ASCII 
that
  has been fixed in r290618 and lead to a rewrite of ascii.c based on none.c.
  
  ascii.c was wrongly reintroduced in r290620 without proper svn operation which
  lost the history.
  
  Reported by:  ache, danfe

Replaced:
  head/lib/libc/locale/ascii.c
     - copied, changed from r298272, head/lib/libc/locale/none.c

Copied and modified: head/lib/libc/locale/ascii.c (from r298272, 
head/lib/libc/locale/none.c)
==============================================================================
--- head/lib/libc/locale/none.c Tue Apr 19 15:18:31 2016        (r298272, copy 
source)
+++ head/lib/libc/locale/ascii.c        Thu Apr 21 06:27:06 2016        
(r298395)
@@ -1,4 +1,4 @@
-/*-
+/*
  * Copyright 2013 Garrett D'Amore <[email protected]>
  * Copyright 2010 Nexenta Systems, Inc.  All rights reserved.
  * Copyright (c) 2002-2004 Tim J. Robbins. All rights reserved.
@@ -36,11 +36,10 @@
  * 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
  */
 
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)none.c     8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
 #include <sys/cdefs.h>
 __FBSDID("$FreeBSD$");
 
@@ -54,41 +53,35 @@ __FBSDID("$FreeBSD$");
 #include <wchar.h>
 #include "mblocal.h"
 
-static size_t  _none_mbrtowc(wchar_t * __restrict, const char * __restrict,
+static size_t  _ascii_mbrtowc(wchar_t * __restrict, const char * __restrict,
                    size_t, mbstate_t * __restrict);
-static int     _none_mbsinit(const mbstate_t *);
-static size_t  _none_mbsnrtowcs(wchar_t * __restrict dst,
+static int     _ascii_mbsinit(const mbstate_t *);
+static size_t  _ascii_mbsnrtowcs(wchar_t * __restrict dst,
                    const char ** __restrict src, size_t nms, size_t len,
                    mbstate_t * __restrict ps __unused);
-static size_t  _none_wcrtomb(char * __restrict, wchar_t,
+static size_t  _ascii_wcrtomb(char * __restrict, wchar_t,
                    mbstate_t * __restrict);
-static size_t  _none_wcsnrtombs(char * __restrict, const wchar_t ** __restrict,
+static size_t  _ascii_wcsnrtombs(char * __restrict, const wchar_t ** 
__restrict,
                    size_t, size_t, mbstate_t * __restrict);
 
-/* setup defaults */
-
-int __mb_cur_max = 1;
-int __mb_sb_limit = 256; /* Expected to be <= _CACHED_RUNES */
-
 int
-_none_init(struct xlocale_ctype *l, _RuneLocale *rl)
+_ascii_init(struct xlocale_ctype *l, _RuneLocale *rl)
 {
 
-       l->__mbrtowc = _none_mbrtowc;
-       l->__mbsinit = _none_mbsinit;
-       l->__mbsnrtowcs = _none_mbsnrtowcs;
-       l->__wcrtomb = _none_wcrtomb;
-       l->__wcsnrtombs = _none_wcsnrtombs;
+       l->__mbrtowc = _ascii_mbrtowc;
+       l->__mbsinit = _ascii_mbsinit;
+       l->__mbsnrtowcs = _ascii_mbsnrtowcs;
+       l->__wcrtomb = _ascii_wcrtomb;
+       l->__wcsnrtombs = _ascii_wcsnrtombs;
        l->runes = rl;
        l->__mb_cur_max = 1;
-       l->__mb_sb_limit = 256;
+       l->__mb_sb_limit = 128;
        return(0);
 }
 
 static int
-_none_mbsinit(const mbstate_t *ps __unused)
+_ascii_mbsinit(const mbstate_t *ps __unused)
 {
-
        /*
         * Encoding is not state dependent - we are always in the
         * initial state.
@@ -97,30 +90,33 @@ _none_mbsinit(const mbstate_t *ps __unus
 }
 
 static size_t
-_none_mbrtowc(wchar_t * __restrict pwc, const char * __restrict s, size_t n,
+_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);
        if (n == 0)
                /* Incomplete multibyte sequence */
                return ((size_t)-2);
+       if (*s & 0x80) {
+               errno = EILSEQ;
+               return ((size_t)-1);
+       }
        if (pwc != NULL)
                *pwc = (unsigned char)*s;
        return (*s == '\0' ? 0 : 1);
 }
 
 static size_t
-_none_wcrtomb(char * __restrict s, wchar_t wc,
+_ascii_wcrtomb(char * __restrict s, wchar_t wc,
     mbstate_t * __restrict ps __unused)
 {
 
        if (s == NULL)
                /* Reset to initial shift state (no-op) */
                return (1);
-       if (wc < 0 || wc > UCHAR_MAX) {
+       if (wc < 0 || wc > 127) {
                errno = EILSEQ;
                return ((size_t)-1);
        }
@@ -129,7 +125,7 @@ _none_wcrtomb(char * __restrict s, wchar
 }
 
 static size_t
-_none_mbsnrtowcs(wchar_t * __restrict dst, const char ** __restrict src,
+_ascii_mbsnrtowcs(wchar_t * __restrict dst, const char ** __restrict src,
     size_t nms, size_t len, mbstate_t * __restrict ps __unused)
 {
        const char *s;
@@ -137,12 +133,23 @@ _none_mbsnrtowcs(wchar_t * __restrict ds
 
        if (dst == NULL) {
                s = memchr(*src, '\0', nms);
-               return (s != NULL ? s - *src : nms);
+               if (s == NULL)
+                       return (nms);
+
+               if (*s & 0x80) {
+                       errno = EILSEQ;
+                       return ((size_t)-1);
+               }
+               return (s - *src);
        }
 
        s = *src;
        nchr = 0;
        while (len-- > 0 && nms-- > 0) {
+               if (*s & 0x80) {
+                       errno = EILSEQ;
+                       return ((size_t)-1);
+               }
                if ((*dst++ = (unsigned char)*s++) == L'\0') {
                        *src = NULL;
                        return (nchr);
@@ -154,7 +161,7 @@ _none_mbsnrtowcs(wchar_t * __restrict ds
 }
 
 static size_t
-_none_wcsnrtombs(char * __restrict dst, const wchar_t ** __restrict src,
+_ascii_wcsnrtombs(char * __restrict dst, const wchar_t ** __restrict src,
     size_t nwc, size_t len, mbstate_t * __restrict ps __unused)
 {
        const wchar_t *s;
@@ -162,7 +169,7 @@ _none_wcsnrtombs(char * __restrict dst, 
 
        if (dst == NULL) {
                for (s = *src; nwc > 0 && *s != L'\0'; s++, nwc--) {
-                       if (*s < 0 || *s > UCHAR_MAX) {
+                       if (*s < 0 || *s > 127) {
                                errno = EILSEQ;
                                return ((size_t)-1);
                        }
@@ -173,7 +180,7 @@ _none_wcsnrtombs(char * __restrict dst, 
        s = *src;
        nchr = 0;
        while (len-- > 0 && nwc-- > 0) {
-               if (*s < 0 || *s > UCHAR_MAX) {
+               if (*s < 0 || *s > 127) {
                        errno = EILSEQ;
                        return ((size_t)-1);
                }
@@ -186,29 +193,3 @@ _none_wcsnrtombs(char * __restrict dst, 
        *src = s;
        return (nchr);
 }
-
-/* setup defaults */
-
-struct xlocale_ctype __xlocale_global_ctype = {
-       {{0}, "C"},
-       (_RuneLocale*)&_DefaultRuneLocale,
-       _none_mbrtowc,
-       _none_mbsinit,
-       _none_mbsnrtowcs,
-       _none_wcrtomb,
-       _none_wcsnrtombs,
-       1, /* __mb_cur_max, */
-       256 /* __mb_sb_limit */
-};
-
-struct xlocale_ctype __xlocale_C_ctype = {
-       {{0}, "C"},
-       (_RuneLocale*)&_DefaultRuneLocale,
-       _none_mbrtowc,
-       _none_mbsinit,
-       _none_mbsnrtowcs,
-       _none_wcrtomb,
-       _none_wcsnrtombs,
-       1, /* __mb_cur_max, */
-       256 /* __mb_sb_limit */
-};
_______________________________________________
[email protected] mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "[email protected]"

Reply via email to