diff options
author | Stefan Sperling <stsp@cvs.openbsd.org> | 2013-08-28 16:53:35 +0000 |
---|---|---|
committer | Stefan Sperling <stsp@cvs.openbsd.org> | 2013-08-28 16:53:35 +0000 |
commit | 12c36af30d7c3ea2a169055ac988abbf0e9541dd (patch) | |
tree | fc08e23021ebb0e0cd2eadb551d00a71438dc45b /lib/libc/locale | |
parent | 6c7a7ca6bb3f3f7dff8d9e21791f5f47ec85f441 (diff) |
Allow setlocale(LC_MESSAGES, ...); to succeed. This always returned an
error, but that makes some ports (e.g. GNOME) freak out. We can allow
any message language to be used as long as the encoding specified as
part of the locale name is supported (i.e. listed in locale -m output).
The primary users of LC_MESSAGES are catopen(3) and gettext(3), which
already worked without this change.
ok ajacoutot, naddy, matthew
Diffstat (limited to 'lib/libc/locale')
-rw-r--r-- | lib/libc/locale/Makefile.inc | 6 | ||||
-rw-r--r-- | lib/libc/locale/setlocale.c | 33 |
2 files changed, 37 insertions, 2 deletions
diff --git a/lib/libc/locale/Makefile.inc b/lib/libc/locale/Makefile.inc index abf8d3a19bb..3cb81e31bd9 100644 --- a/lib/libc/locale/Makefile.inc +++ b/lib/libc/locale/Makefile.inc @@ -1,8 +1,11 @@ -# $OpenBSD: Makefile.inc,v 1.18 2012/06/07 19:47:40 matthew Exp $ +# $OpenBSD: Makefile.inc,v 1.19 2013/08/28 16:53:34 stsp Exp $ # locale sources .PATH: ${LIBCSRCDIR}/arch/${MACHINE_CPU}/locale ${LIBCSRCDIR}/locale +# for LOCALECHARSETS +.include "${.CURDIR}/../../share/locale/ctype/Makefile.inc" + SRCS+= btowc.c _def_messages.c _def_monetary.c _def_numeric.c _def_time.c \ localeconv.c nl_langinfo.c setlocale.c iswctype.c __mb_cur_max.c \ mblen.c mbrlen.c mbstowcs.c mbtowc.c multibyte_citrus.c wcscoll.c \ @@ -40,3 +43,4 @@ MLINKS+=setlocale.3 localeconv.3 \ wcsrtombs.3 wcsnrtombs.3 CFLAGS+=-I${.CURDIR} -I${LIBCSRCDIR}/citrus +CFLAGS+=-DLOCALE_CHARSETS="\"${LOCALECHARSETS}\"" diff --git a/lib/libc/locale/setlocale.c b/lib/libc/locale/setlocale.c index 3fe0b7345df..4da2f88779c 100644 --- a/lib/libc/locale/setlocale.c +++ b/lib/libc/locale/setlocale.c @@ -1,4 +1,4 @@ -/* $OpenBSD: setlocale.c,v 1.19 2013/06/01 20:02:53 stsp Exp $ */ +/* $OpenBSD: setlocale.c,v 1.20 2013/08/28 16:53:34 stsp Exp $ */ /* * Copyright (c) 1991, 1993 * The Regents of the University of California. All rights reserved. @@ -209,6 +209,35 @@ revert_to_default(int category) } static int +set_lc_messages_locale(const char *locname) +{ + const char *charset; + char charsets[sizeof(LOCALE_CHARSETS)]; + char *s = charsets; + const char *dot, *loc_encoding; + + /* Assumes "language[_territory][.codeset]" locale name. */ + dot = strrchr(locname, '.'); + if (dot == NULL) + return -1; + loc_encoding = dot + 1; + + /* Allow message catalogs in encodings supported by LC_CTYPE. + * We don't care about the language name since it is application + * specific. */ + memcpy(charsets, LOCALE_CHARSETS, sizeof(charsets)); + do { + charset = strsep(&s, " \t"); + if (charset && charset[0]) { + if (strcmp(loc_encoding, charset) == 0) + return 0; + } + } while (charset); + + return -1; +} + +static int load_locale_sub(int category, const char *locname, int isspecial) { /* check for the default locales */ @@ -230,6 +259,8 @@ load_locale_sub(int category, const char *locname, int isspecial) break; case LC_MESSAGES: + return set_lc_messages_locale(locname); + case LC_COLLATE: case LC_MONETARY: case LC_NUMERIC: |