[git commit 0_9_30] locale: gen_wc8bit: try to find UTF8 locale automatically

Mike Frysinger vapier at gentoo.org
Sat Oct 10 16:44:02 UTC 2009


commit: http://git.uclibc.org/uClibc/commit/?id=9966f4d96abeade57f1eccd3d0281aa03de0df1c
branch: http://git.uclibc.org/uClibc/commit/?id=refs/heads/0_9_30

Rather than require everyone to have en_US.UTF-8 when we really need any
UTF8 locale, do a scan for possible UTF8 locales if the default en_US does
not exist.  Hopefully this should make the utility "just work" for most
people.

Reported-by: Daniel Cordero <theappleman at gmail.com>
Signed-off-by: Mike Frysinger <vapier at gentoo.org>
Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop at gmail.com>
---
 extra/locale/gen_wc8bit.c |   25 ++++++++++++++++++++++++-
 1 files changed, 24 insertions(+), 1 deletions(-)

diff --git a/extra/locale/gen_wc8bit.c b/extra/locale/gen_wc8bit.c
index 2fdcb68..569441f 100644
--- a/extra/locale/gen_wc8bit.c
+++ b/extra/locale/gen_wc8bit.c
@@ -98,8 +98,31 @@ int main(int argc, char **argv)
 	int total_size = 0;
 
 	if (!setlocale(LC_CTYPE, "en_US.UTF-8")) {
-		printf("setlocale(LC_CTYPE,\"en_US.UTF-8\") failed!\n");
+		/* Silly foreigners disabling en_US locales */
+		FILE *fp = popen("locale -a", "r");
+		if (!fp)
+			goto locale_failure;
+
+		while (!feof(fp)) {
+			char buf[256];
+			size_t len;
+
+			if (fgets(buf, sizeof(buf) - 10, fp) == NULL)
+				goto locale_failure;
+
+			len = strlen(buf);
+			if (buf[len - 1] == '\n')
+				buf[--len] = '\0';
+			strcat(buf, ".UTF8");
+			if (setlocale(LC_CTYPE, buf))
+				goto locale_success;
+		}
+
+ locale_failure:
+		printf("could not find a UTF8 locale ... please enable en_US.UTF-8\n");
 		return EXIT_FAILURE;
+ locale_success:
+		pclose(fp);
 	}
 
 	if (!(out = fopen("c8tables.h","w"))) {
-- 
1.6.3.3



More information about the uClibc-cvs mailing list