From: Vincent Hanquez Date: Mon, 9 Feb 2009 17:25:57 +0000 (+0000) Subject: locale.patch X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=refs%2Fremotes%2Forigin%2Fmaster;p=xenclient%2Fuclibc.git locale.patch --- diff --git a/Rules.mak b/Rules.mak index d3cda90..39e7ffb 100644 --- a/Rules.mak +++ b/Rules.mak @@ -91,7 +91,13 @@ ifneq ($(EXTRAVERSION),) VERSION := $(VERSION)$(EXTRAVERSION) endif # Ensure consistent sort order, 'gcc -print-search-dirs' behavior, etc. -LC_ALL := C +# To allow gen_wc8bit.c to compile without US UTF installed, LC_CTYPE can be +# set to another UTF (eg. en_GB.utf8) before typing "make". However, loading +# LC_ALL here causes the charmap to be replaced with ANSI_X3.4-1968. This +# breaks building gen_wc8bit.c (when the previously mentioned US UTF isn't +# installed). Hack workaround is to assume all will be OK without all +# locale categories set to 'C'. +# LC_ALL := C export MAJOR_VERSION MINOR_VERSION SUBLEVEL VERSION LC_ALL LIBC := libc diff --git a/extra/locale/gen_wc8bit.c b/extra/locale/gen_wc8bit.c index 20f8f64..eaa53ce 100644 --- a/extra/locale/gen_wc8bit.c +++ b/extra/locale/gen_wc8bit.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -81,6 +82,7 @@ int main(int argc, char **argv) { FILE *fp; FILE *out; + char *ctype; charset_data csd[30]; unsigned long max_wchar; unsigned char *p; @@ -97,7 +99,26 @@ int main(int argc, char **argv) int codeset_list_end = 0; int total_size = 0; - if (!setlocale(LC_CTYPE, "en_US.UTF-8")) { + /* + * Kludge to allow building on a system without the US UTF installed. + * If cannot load the US UTF, then restore the char encoding and + * continue if it is a UTF encoding. + */ + + ctype = setlocale(LC_CTYPE, ""); + if (ctype != NULL) { + i = strlen(ctype); + if (i < sizeof (buf)) { + memcpy(buf, ctype, i + 1); + } else { + ctype = NULL; + } + } + if (setlocale(LC_CTYPE, "en_US.UTF-8") == NULL && ctype != NULL) { + (void) setlocale(LC_CTYPE, buf); + } + if (strcmp(nl_langinfo(CODESET), "UTF-8") != 0 && + setlocale(LC_CTYPE, "en_US.UTF-8") == NULL) { printf("setlocale(LC_CTYPE,\"en_US.UTF-8\") failed!\n"); return EXIT_FAILURE; }