summaryrefslogtreecommitdiff
path: root/libc/stdlib
diff options
context:
space:
mode:
authorCarmelo Amoroso <carmelo.amoroso@st.com>2008-09-09 13:01:58 +0000
committerCarmelo Amoroso <carmelo.amoroso@st.com>2008-09-09 13:01:58 +0000
commita79016198c859a3388584ac7782d760f349e2d67 (patch)
treead74465aca5c92984b7314970818cbb775dc80c3 /libc/stdlib
parentd673a24ff2e988888cabfd37d48dc72cbada95a5 (diff)
Fix some locale multibyte tests failures ad below:
libc/stdlib/_strtod.c -> tst_wcstod; libc/stdlib/stdlib.c -> tst_mblen, tst_mbtowc, tst_wctomb; libc/stdio/_scanf.c -> tst_swscanf; libc/string/strncmp.c -> tst_wcsncmp; libc/misc/wchar/wchar.c -> tst_mbrlen, tst_mbrtowc, tst_wcswidth. Signed-off-by: Filippo Arcidiacono <filippo.arcidiacono@st.com> Signed-off-by: Carmelo Amoroso <carmelo.amoroso@st.com>
Diffstat (limited to 'libc/stdlib')
-rw-r--r--libc/stdlib/_strtod.c2
-rw-r--r--libc/stdlib/stdlib.c64
2 files changed, 50 insertions, 16 deletions
diff --git a/libc/stdlib/_strtod.c b/libc/stdlib/_strtod.c
index 73a7ed7c1..1b2adc986 100644
--- a/libc/stdlib/_strtod.c
+++ b/libc/stdlib/_strtod.c
@@ -234,7 +234,7 @@ __fpmax_t attribute_hidden __XL_NPP(__strtofpmax)(const Wchar *str, Wchar **endp
#endif
#ifdef __UCLIBC_HAS_LOCALE__
#if defined(L___wcstofpmax) || defined(L___wcstofpmax_l)
- wchar_t decpt_wc = __LOCALE_PTR->decimal_point;
+ wchar_t decpt_wc = __LOCALE_PTR->decimal_point_wc;
#else
const char *decpt = __LOCALE_PTR->decimal_point;
int decpt_len = __LOCALE_PTR->decimal_point_len;
diff --git a/libc/stdlib/stdlib.c b/libc/stdlib/stdlib.c
index 15292ceed..68796656a 100644
--- a/libc/stdlib/stdlib.c
+++ b/libc/stdlib/stdlib.c
@@ -929,6 +929,30 @@ size_t _stdlib_mb_cur_max(void)
libc_hidden_def(_stdlib_mb_cur_max)
#endif
+
+#ifdef __UCLIBC_HAS_LOCALE__
+/*
+ * The following function return 1 if the encoding is stateful, 0 if stateless.
+ * To note, until now all the supported encoding are stateless.
+ */
+
+static inline int is_stateful(unsigned char encoding)
+{
+ switch (encoding)
+ {
+ case __ctype_encoding_7_bit:
+ case __ctype_encoding_utf8:
+ case __ctype_encoding_8_bit:
+ return 0;
+ default:
+ assert(0);
+ return -1;
+ }
+}
+#else
+#define is_stateful(encoding) 0
+#endif
+
/**********************************************************************/
#ifdef L_mblen
@@ -941,13 +965,17 @@ int mblen(register const char *s, size_t n)
if (!s) {
state.__mask = 0;
-#ifdef __CTYPE_HAS_UTF_8_LOCALES
- return ENCODING == __ctype_encoding_utf8;
-#else
- return 0;
-#endif
+ /*
+ In this case we have to return 0 because the only multibyte supported encoding
+ is utf-8, that is a stateless encoding. See mblen() documentation.
+ */
+ return is_stateful(ENCODING);
}
+ if (*s == '\0')
+ /* According to the ISO C 89 standard this is the expected behaviour. */
+ return 0;
+
if ((r = mbrlen(s, n, &state)) == (size_t) -2) {
/* TODO: Should we set an error state? */
state.__wc = 0xffffU; /* Make sure we're in an error state. */
@@ -969,13 +997,18 @@ int mbtowc(wchar_t *__restrict pwc, register const char *__restrict s, size_t n)
if (!s) {
state.__mask = 0;
-#ifdef __CTYPE_HAS_UTF_8_LOCALES
- return ENCODING == __ctype_encoding_utf8;
-#else
- return 0;
-#endif
+ /*
+ In this case we have to return 0 because the only multibyte supported encoding
+ is utf-8, that is a stateless encoding. See mbtowc() documentation.
+ */
+
+ return is_stateful(ENCODING);
}
+ if (*s == '\0')
+ /* According to the ISO C 89 standard this is the expected behaviour. */
+ return 0;
+
if ((r = mbrtowc(pwc, s, n, &state)) == (size_t) -2) {
/* TODO: Should we set an error state? */
state.__wc = 0xffffU; /* Make sure we're in an error state. */
@@ -996,11 +1029,12 @@ int wctomb(register char *__restrict s, wchar_t swc)
{
return (!s)
?
-#ifdef __CTYPE_HAS_UTF_8_LOCALES
- (ENCODING == __ctype_encoding_utf8)
-#else
- 0 /* Encoding is stateless. */
-#endif
+ /*
+ In this case we have to return 0 because the only multibyte supported encoding
+ is utf-8, that is a stateless encoding. See wctomb() documentation.
+ */
+
+ is_stateful(ENCODING)
: ((ssize_t) wcrtomb(s, swc, NULL));
}