Print this page
2964 need POSIX 2008 locale object support
Reviewed by: Robert Mustacchi <rm@joyent.com>
Reviewed by: Gordon Ross <gordon.ross@nexenta.com>
Approved by: TBD

@@ -1,6 +1,7 @@
 /*
+ * Copyright 2013 Garrett D'Amore <garrett@damore.org>
  * Copyright 2011 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.
  *

@@ -38,12 +39,12 @@
 #include <stdlib.h>
 #include <string.h>
 #include <wchar.h>
 #include <sys/types.h>
 #include <sys/euc.h>
-#include "runetype.h"
 #include "mblocal.h"
+#include "lctype.h"
 
 static size_t   _EUC_mbrtowc_impl(wchar_t *_RESTRICT_KYWD,
     const char *_RESTRICT_KYWD,
     size_t, mbstate_t *_RESTRICT_KYWD, uint8_t, uint8_t, uint8_t, uint8_t);
 static size_t   _EUC_wcrtomb_impl(char *_RESTRICT_KYWD, wchar_t,

@@ -59,48 +60,75 @@
                     const char *_RESTRICT_KYWD,
                     size_t, mbstate_t *_RESTRICT_KYWD);
 static size_t   _EUC_TW_mbrtowc(wchar_t *_RESTRICT_KYWD,
                     const char *_RESTRICT_KYWD,
                     size_t, mbstate_t *_RESTRICT_KYWD);
+
 static size_t   _EUC_CN_wcrtomb(char *_RESTRICT_KYWD, wchar_t,
                     mbstate_t *_RESTRICT_KYWD);
 static size_t   _EUC_JP_wcrtomb(char *_RESTRICT_KYWD, wchar_t,
                     mbstate_t *_RESTRICT_KYWD);
 static size_t   _EUC_KR_wcrtomb(char *_RESTRICT_KYWD, wchar_t,
                     mbstate_t *_RESTRICT_KYWD);
 static size_t   _EUC_TW_wcrtomb(char *_RESTRICT_KYWD, wchar_t,
                     mbstate_t *_RESTRICT_KYWD);
+
+static size_t   _EUC_CN_mbsnrtowcs(wchar_t *_RESTRICT_KYWD,
+                    const char **_RESTRICT_KYWD, size_t, size_t,
+                    mbstate_t *_RESTRICT_KYWD);
+static size_t   _EUC_JP_mbsnrtowcs(wchar_t *_RESTRICT_KYWD,
+                    const char **_RESTRICT_KYWD, size_t, size_t,
+                    mbstate_t *_RESTRICT_KYWD);
+static size_t   _EUC_KR_mbsnrtowcs(wchar_t *_RESTRICT_KYWD,
+                    const char **_RESTRICT_KYWD, size_t, size_t,
+                    mbstate_t *_RESTRICT_KYWD);
+static size_t   _EUC_TW_mbsnrtowcs(wchar_t *_RESTRICT_KYWD,
+                    const char **_RESTRICT_KYWD, size_t, size_t,
+                    mbstate_t *_RESTRICT_KYWD);
+
+static size_t   _EUC_CN_wcsnrtombs(char *_RESTRICT_KYWD,
+                    const wchar_t **_RESTRICT_KYWD, size_t, size_t,
+                    mbstate_t *_RESTRICT_KYWD);
+static size_t   _EUC_JP_wcsnrtombs(char *_RESTRICT_KYWD,
+                    const wchar_t **_RESTRICT_KYWD, size_t, size_t,
+                    mbstate_t *_RESTRICT_KYWD);
+static size_t   _EUC_KR_wcsnrtombs(char *_RESTRICT_KYWD,
+                    const wchar_t **_RESTRICT_KYWD, size_t, size_t,
+                    mbstate_t *_RESTRICT_KYWD);
+static size_t   _EUC_TW_wcsnrtombs(char *_RESTRICT_KYWD,
+                    const wchar_t **_RESTRICT_KYWD, size_t, size_t,
+                    mbstate_t *_RESTRICT_KYWD);
+
 static int      _EUC_mbsinit(const mbstate_t *);
 
 typedef struct {
         wchar_t ch;
         int     set;
         int     want;
 } _EucState;
 
-static int
+int
 _EUC_mbsinit(const mbstate_t *ps)
 {
 
         return (ps == NULL || ((const _EucState *)ps)->want == 0);
 }
 
 /*
  * EUC-CN uses CS0, CS1 and CS2 (4 bytes).
  */
-int
-_EUC_CN_init(_RuneLocale *rl)
+void
+_EUC_CN_init(struct lc_ctype *lct)
 {
-        __mbrtowc = _EUC_CN_mbrtowc;
-        __wcrtomb = _EUC_CN_wcrtomb;
-        __mbsinit = _EUC_mbsinit;
+        lct->lc_mbrtowc = _EUC_CN_mbrtowc;
+        lct->lc_wcrtomb = _EUC_CN_wcrtomb;
+        lct->lc_mbsnrtowcs = _EUC_CN_mbsnrtowcs;
+        lct->lc_wcsnrtombs = _EUC_CN_wcsnrtombs;
+        lct->lc_mbsinit = _EUC_mbsinit;
 
-        _CurrentRuneLocale = rl;
-
-        __ctype[520] = 4;
-        charset_is_ascii = 0;
-        return (0);
+        lct->lc_max_mblen = 4;
+        lct->lc_is_ascii = 0;
 }
 
 static size_t
 _EUC_CN_mbrtowc(wchar_t *_RESTRICT_KYWD pwc, const char *_RESTRICT_KYWD s,
     size_t n, mbstate_t *_RESTRICT_KYWD ps)

@@ -107,31 +135,45 @@
 {
         return (_EUC_mbrtowc_impl(pwc, s, n, ps, SS2, 4, 0, 0));
 }
 
 static size_t
+_EUC_CN_mbsnrtowcs(wchar_t *_RESTRICT_KYWD dst,
+    const char **_RESTRICT_KYWD src,
+    size_t nms, size_t len, mbstate_t *_RESTRICT_KYWD ps)
+{
+        return (__mbsnrtowcs_std(dst, src, nms, len, ps, _EUC_CN_mbrtowc));
+}
+
+static size_t
 _EUC_CN_wcrtomb(char *_RESTRICT_KYWD s, wchar_t wc,
     mbstate_t *_RESTRICT_KYWD ps)
 {
         return (_EUC_wcrtomb_impl(s, wc, ps, SS2, 4, 0, 0));
 }
 
+static size_t
+_EUC_CN_wcsnrtombs(char *_RESTRICT_KYWD dst, const wchar_t **_RESTRICT_KYWD src,
+        size_t nwc, size_t len, mbstate_t *_RESTRICT_KYWD ps)
+{
+        return (__wcsnrtombs_std(dst, src, nwc, len, ps, _EUC_CN_wcrtomb));
+}
+
 /*
  * EUC-KR uses only CS0 and CS1.
  */
-int
-_EUC_KR_init(_RuneLocale *rl)
+void
+_EUC_KR_init(struct lc_ctype *lct)
 {
-        __mbrtowc = _EUC_KR_mbrtowc;
-        __wcrtomb = _EUC_KR_wcrtomb;
-        __mbsinit = _EUC_mbsinit;
+        lct->lc_mbrtowc = _EUC_KR_mbrtowc;
+        lct->lc_wcrtomb = _EUC_KR_wcrtomb;
+        lct->lc_mbsnrtowcs = _EUC_KR_mbsnrtowcs;
+        lct->lc_wcsnrtombs = _EUC_KR_wcsnrtombs;
+        lct->lc_mbsinit = _EUC_mbsinit;
 
-        _CurrentRuneLocale = rl;
-
-        __ctype[520] = 2;
-        charset_is_ascii = 0;
-        return (0);
+        lct->lc_max_mblen = 2;
+        lct->lc_is_ascii = 0;
 }
 
 static size_t
 _EUC_KR_mbrtowc(wchar_t *_RESTRICT_KYWD pwc, const char *_RESTRICT_KYWD s,
     size_t n, mbstate_t *_RESTRICT_KYWD ps)

@@ -138,31 +180,45 @@
 {
         return (_EUC_mbrtowc_impl(pwc, s, n, ps, 0, 0, 0, 0));
 }
 
 static size_t
+_EUC_KR_mbsnrtowcs(wchar_t *_RESTRICT_KYWD dst,
+    const char **_RESTRICT_KYWD src,
+    size_t nms, size_t len, mbstate_t *_RESTRICT_KYWD ps)
+{
+        return (__mbsnrtowcs_std(dst, src, nms, len, ps, _EUC_KR_mbrtowc));
+}
+
+static size_t
 _EUC_KR_wcrtomb(char *_RESTRICT_KYWD s, wchar_t wc,
     mbstate_t *_RESTRICT_KYWD ps)
 {
         return (_EUC_wcrtomb_impl(s, wc, ps, 0, 0, 0, 0));
 }
 
+static size_t
+_EUC_KR_wcsnrtombs(char *_RESTRICT_KYWD dst, const wchar_t **_RESTRICT_KYWD src,
+        size_t nwc, size_t len, mbstate_t *_RESTRICT_KYWD ps)
+{
+        return (__wcsnrtombs_std(dst, src, nwc, len, ps, _EUC_KR_wcrtomb));
+}
+
 /*
  * EUC-JP uses CS0, CS1, CS2, and CS3.
  */
-int
-_EUC_JP_init(_RuneLocale *rl)
+void
+_EUC_JP_init(struct lc_ctype *lct)
 {
-        __mbrtowc = _EUC_JP_mbrtowc;
-        __wcrtomb = _EUC_JP_wcrtomb;
-        __mbsinit = _EUC_mbsinit;
+        lct->lc_mbrtowc = _EUC_JP_mbrtowc;
+        lct->lc_wcrtomb = _EUC_JP_wcrtomb;
+        lct->lc_mbsnrtowcs = _EUC_JP_mbsnrtowcs;
+        lct->lc_wcsnrtombs = _EUC_JP_wcsnrtombs;
+        lct->lc_mbsinit = _EUC_mbsinit;
 
-        _CurrentRuneLocale = rl;
-
-        __ctype[520] = 3;
-        charset_is_ascii = 0;
-        return (0);
+        lct->lc_max_mblen = 3;
+        lct->lc_is_ascii = 0;
 }
 
 static size_t
 _EUC_JP_mbrtowc(wchar_t *_RESTRICT_KYWD pwc, const char *_RESTRICT_KYWD s,
     size_t n, mbstate_t *_RESTRICT_KYWD ps)

@@ -169,31 +225,45 @@
 {
         return (_EUC_mbrtowc_impl(pwc, s, n, ps, SS2, 2, SS3, 3));
 }
 
 static size_t
+_EUC_JP_mbsnrtowcs(wchar_t *_RESTRICT_KYWD dst,
+    const char **_RESTRICT_KYWD src,
+    size_t nms, size_t len, mbstate_t *_RESTRICT_KYWD ps)
+{
+        return (__mbsnrtowcs_std(dst, src, nms, len, ps, _EUC_JP_mbrtowc));
+}
+
+static size_t
 _EUC_JP_wcrtomb(char *_RESTRICT_KYWD s, wchar_t wc,
     mbstate_t *_RESTRICT_KYWD ps)
 {
         return (_EUC_wcrtomb_impl(s, wc, ps, SS2, 2, SS3, 3));
 }
 
+static size_t
+_EUC_JP_wcsnrtombs(char *_RESTRICT_KYWD dst, const wchar_t **_RESTRICT_KYWD src,
+        size_t nwc, size_t len, mbstate_t *_RESTRICT_KYWD ps)
+{
+        return (__wcsnrtombs_std(dst, src, nwc, len, ps, _EUC_JP_wcrtomb));
+}
+
 /*
  * EUC-TW uses CS0, CS1, and CS2.
  */
-int
-_EUC_TW_init(_RuneLocale *rl)
+void
+_EUC_TW_init(struct lc_ctype *lct)
 {
-        __mbrtowc = _EUC_TW_mbrtowc;
-        __wcrtomb = _EUC_TW_wcrtomb;
-        __mbsinit = _EUC_mbsinit;
+        lct->lc_mbrtowc = _EUC_TW_mbrtowc;
+        lct->lc_wcrtomb = _EUC_TW_wcrtomb;
+        lct->lc_mbsnrtowcs = _EUC_TW_mbsnrtowcs;
+        lct->lc_wcsnrtombs = _EUC_TW_wcsnrtombs;
+        lct->lc_mbsinit = _EUC_mbsinit;
 
-        _CurrentRuneLocale = rl;
-
-        __ctype[520] = 4;
-        charset_is_ascii = 0;
-        return (0);
+        lct->lc_max_mblen = 4;
+        lct->lc_is_ascii = 0;
 }
 
 static size_t
 _EUC_TW_mbrtowc(wchar_t *_RESTRICT_KYWD pwc, const char *_RESTRICT_KYWD s,
     size_t n, mbstate_t *_RESTRICT_KYWD ps)

@@ -200,16 +270,31 @@
 {
         return (_EUC_mbrtowc_impl(pwc, s, n, ps, SS2, 4, 0, 0));
 }
 
 static size_t
+_EUC_TW_mbsnrtowcs(wchar_t *_RESTRICT_KYWD dst,
+        const char **_RESTRICT_KYWD src,
+        size_t nms, size_t len, mbstate_t *_RESTRICT_KYWD ps)
+{
+        return (__mbsnrtowcs_std(dst, src, nms, len, ps, _EUC_TW_mbrtowc));
+}
+
+static size_t
 _EUC_TW_wcrtomb(char *_RESTRICT_KYWD s, wchar_t wc,
     mbstate_t *_RESTRICT_KYWD ps)
 {
         return (_EUC_wcrtomb_impl(s, wc, ps, SS2, 4, 0, 0));
 }
 
+static size_t
+_EUC_TW_wcsnrtombs(char *_RESTRICT_KYWD dst, const wchar_t **_RESTRICT_KYWD src,
+        size_t nwc, size_t len, mbstate_t *_RESTRICT_KYWD ps)
+{
+        return (__wcsnrtombs_std(dst, src, nwc, len, ps, _EUC_TW_wcrtomb));
+}
+
 /*
  * Common EUC code.
  */
 
 static size_t