The attached test fails (in 5.2, 5.3 and current), producing:
locale es_CO.UTF-8/es_CO.UTF-8/C/C/C/es_CO.UTF-8
__mb_cur_max=4
locale es_CO.ISO8859-1/es_CO.ISO8859-1/C/C/C/es_CO.ISO8859-1
__mb_cur_max=1
locale es_CO.UTF-8/es_CO.UTF-8/C/C/C/es_CO.UTF-8
__mb_cur_max=1
assertion "__mb_cur_max == 4" failed: file "prob_mb_cur_max.c", line 21,
function "main"
The attached patch fixes the problem.
By the way, in FreeBSD the structure xlocale_ctype has a member __mb_cur_max,
and __mb_cur_max for UTF-8 is 6.
--
Dios, gracias por tu amor infinito.
--
Vladimir Támara Patiño. http://vtamara.pasosdeJesus.org/
http://www.pasosdejesus.org/dominio_publico_colombia.html
#include <assert.h>
#include <locale.h>
#include <stdio.h>
#include <stdlib.h>
int main() {
char *nl;
nl = setlocale(LC_ALL, "es_CO.UTF-8");
printf("locale %s\n", nl);
printf("__mb_cur_max=%i\n", __mb_cur_max);
assert(__mb_cur_max == 4);
nl = setlocale(LC_ALL, "es_CO.ISO8859-1");
printf("locale %s\n", nl);
printf("__mb_cur_max=%i\n", __mb_cur_max);
assert(__mb_cur_max == 1);
nl = setlocale(LC_ALL, "es_CO.UTF-8");
printf("locale %s\n", nl);
printf("__mb_cur_max=%i\n", __mb_cur_max);
assert(__mb_cur_max == 4);
return 0;
}
diff -ruN -x CVS -x obj -x *~ src-orig/lib/libc/citrus/citrus_ctype.c
src/lib/libc/citrus/citrus_ctype.c
--- src-orig/lib/libc/citrus/citrus_ctype.c Sat Feb 9 14:26:51 2013
+++ src/lib/libc/citrus/citrus_ctype.c Wed Apr 10 05:40:34 2013
@@ -45,15 +45,24 @@
};
int
+_citrus_ctype_mb_cur_max(char const *encname)
+{
+ if (strcmp(encname, "UTF8") == 0) {
+ return _CITRUS_UTF8_MB_CUR_MAX;
+ }
+ return 1; // If not UTF8 then single byte encoding
+}
+
+int
_citrus_ctype_open(struct _citrus_ctype_rec **rcc, char const *encname)
{
if (!strcmp(encname, "NONE")) {
*rcc = &_citrus_ctype_none;
- __mb_cur_max = 1;
+ __mb_cur_max = _citrus_ctype_mb_cur_max(encname);
return (0);
} else if (!strcmp(encname, "UTF8")) {
*rcc = &_citrus_ctype_utf8;
- __mb_cur_max = _CITRUS_UTF8_MB_CUR_MAX;
+ __mb_cur_max = _citrus_ctype_mb_cur_max(encname);
return (0);
}
diff -ruN -x CVS -x obj -x *~ src-orig/lib/libc/citrus/citrus_ctype.h
src/lib/libc/citrus/citrus_ctype.h
--- src-orig/lib/libc/citrus/citrus_ctype.h Mon Aug 2 13:05:22 2010
+++ src/lib/libc/citrus/citrus_ctype.h Wed Apr 10 05:33:22 2013
@@ -35,6 +35,7 @@
extern struct _citrus_ctype_rec _citrus_ctype_none;
+int _citrus_ctype_mb_cur_max(char const *);
int _citrus_ctype_open(struct _citrus_ctype_rec **, char const *);
#endif
--- src-orig/lib/libc/locale/setrunelocale.c Sat Feb 9 14:26:52 2013
+++ src/lib/libc/locale/setrunelocale.c Wed Apr 10 05:35:23 2013
@@ -100,6 +100,7 @@
#include <unistd.h>
#include <locale.h>
#include <citrus/citrus_ctype.h>
+#include <citrus/citrus_utf8.h>
#include "rune_local.h"
struct localetable {
@@ -195,6 +196,7 @@
found:
_CurrentRuneLocale = rl;
+ __mb_cur_max = _citrus_ctype_mb_cur_max(rl->rl_encoding);
return 0;
}