]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
Respect the thread-specific locale on MacOS X.
authorBruno Haible <bruno@clisp.org>
Sat, 26 Dec 2009 10:56:47 +0000 (11:56 +0100)
committerBruno Haible <bruno@clisp.org>
Sat, 26 Dec 2009 13:44:01 +0000 (14:44 +0100)
17 files changed:
ChangeLog
NEWS
gettext-runtime/ChangeLog
gettext-runtime/NEWS
gettext-runtime/intl/ChangeLog
gettext-runtime/intl/dcigettext.c
gettext-runtime/intl/gettextP.h
gettext-runtime/m4/ChangeLog
gettext-runtime/m4/intl.m4
gettext-tools/ChangeLog
gettext-tools/configure.ac
gettext-tools/tests/ChangeLog
gettext-tools/tests/Makefile.am
gettext-tools/tests/gettext-6
gettext-tools/tests/gettext-6-prg.c
gettext-tools/tests/gettext-7
gettext-tools/tests/gettext-7-prg.c

index cd29077ecf504537a3b91cb3710f44ee9cbe0182..b181384af6beb2c7df2f06ff764ba08de18b9160 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2009-12-26  Bruno Haible  <bruno@clisp.org>
+
+       * NEWS: Mention the use of the thread-specific locale on MacOS X.
+
 2009-12-25  Bruno Haible  <bruno@clisp.org>
 
        * Makefile.am (distcheck-hook): Compare fcntl-o.m4 instead of
diff --git a/NEWS b/NEWS
index e7727a0b060dbe7c386293ccffddb7ea4d814597..57344469c8e00e79888d8617096a23ad9ddf1ad3 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,9 +1,11 @@
 Version 0.18 - January 2008
 
 * Runtime behaviour:
-  On MacOS X and Windows systems, <libintl.h> now extends setlocale() and
-  newlocale() so that their determination of the default locale considers
-  the choice the user has made in the system control panels.
+  - On MacOS X and Windows systems, <libintl.h> now extends setlocale() and
+    newlocale() so that their determination of the default locale considers
+    the choice the user has made in the system control panels.
+  - On MacOS X systems, the gettext()/dgettext()/... functions now respect the
+    locale of the current thread, if a thread-specific locale has been set.
 
 * PO file format:
   There is a new field 'Language' in the header entry.  It denotes the language
index db5fb8bf2be7634aa551139c1019eacea23a5f8d..b86cb54329dbe3bedf4999d4d156d773312277a0 100644 (file)
@@ -1,3 +1,7 @@
+2009-12-26  Bruno Haible  <bruno@clisp.org>
+
+       * NEWS: Mention the use of the thread-specific locale on MacOS X.
+
 2009-05-23  Bruno Haible  <bruno@clisp.org>
 
        * configure.ac (AM_INIT_AUTOMAKE): Add 'silent-rules' option.
index 06f504f22a043f1f0d2168dd062bce9cf13ead32..44974675f84e799c870ad71de551a4312f365a0f 100644 (file)
@@ -3,6 +3,9 @@ Version 0.18 - December 2009
 * On MacOS X and Windows systems, <libintl.h> now extends setlocale() and
   newlocale() so that their determination of the default locale considers
   the choice the user has made in the system control panels.
+
+* On MacOS X systems, the gettext()/dgettext()/... functions now respect the
+  locale of the current thread, if a thread-specific locale has been set.
 \f
 Version 0.16.1 - November 2006
 
index 2841ec8bfe9d09bba44ff11226d6bb465be066f8..398c9b0cced0305ccc532a66af690e347fbba70c 100644 (file)
@@ -1,3 +1,14 @@
+2009-12-26  Bruno Haible  <bruno@clisp.org>
+
+       Use the thread-specific locale also on MacOS X.
+       * dcigettext.c (HAVE_NL_LOCALE_NAME): Remove undef.
+       Don't include <langinfo.h>.
+       (HAVE_PER_THREAD_LOCALE): Define on any platform that has 'uselocale'.
+       (DCIGETTEXT, guess_category_value): Use _nl_locale_name_thread_unsafe
+       instead of glibc specific code.
+       * gettextP.h (gl_locale_name_thread_unsafe): New macro.
+       (_nl_locale_name_thread_unsafe): New declaration.
+
 2009-12-26  Bruno Haible  <bruno@clisp.org>
 
        localename: Fix storage allocation of gl_locale_name_thread's result.
index fc4cd4bd3349a4f16486dfa988602a9a90f06fbe..b2add5db3ecbd258fa92371b1e689bde565919a6 100644 (file)
@@ -1,5 +1,5 @@
 /* Implementation of the internal dcigettext function.
-   Copyright (C) 1995-1999, 2000-2008 Free Software Foundation, Inc.
+   Copyright (C) 1995-1999, 2000-2009 Free Software Foundation, Inc.
 
    This program is free software; you can redistribute it and/or modify it
    under the terms of the GNU Library General Public License as published
@@ -27,9 +27,6 @@
 # include <config.h>
 #endif
 
-/* NL_LOCALE_NAME does not work in glibc-2.4.  Ignore it.  */
-#undef HAVE_NL_LOCALE_NAME
-
 #include <sys/types.h>
 
 #ifdef __GNUC__
@@ -91,9 +88,6 @@ extern int errno;
 #endif
 
 #if !defined _LIBC
-# if HAVE_NL_LOCALE_NAME
-#  include <langinfo.h>
-# endif
 # include "localcharset.h"
 #endif
 
@@ -234,7 +228,7 @@ static void *mempcpy (void *dest, const void *src, size_t n);
 #endif
 
 /* Whether to support different locales in different threads.  */
-#if defined _LIBC || HAVE_NL_LOCALE_NAME || (HAVE_STRUCT___LOCALE_STRUCT___NAMES && defined USE_IN_GETTEXT_TESTS) || defined IN_LIBGLOCALE
+#if defined _LIBC || HAVE_USELOCALE || defined IN_LIBGLOCALE
 # define HAVE_PER_THREAD_LOCALE
 #endif
 
@@ -560,22 +554,11 @@ DCIGETTEXT (const char *domainname, const char *msgid1, const char *msgid2,
 #  ifdef _LIBC
   localename = _strdupa (_current_locale_name (category));
 #  else
-#   if HAVE_NL_LOCALE_NAME
-  /* NL_LOCALE_NAME is public glibc API introduced in glibc-2.4.  */
-  localename = nl_langinfo (NL_LOCALE_NAME (category));
-#   else
-#    if HAVE_STRUCT___LOCALE_STRUCT___NAMES && defined USE_IN_GETTEXT_TESTS
-  /* The __names field is not public glibc API and must therefore not be used
-     in code that is installed in public locations.  */
-  {
-    locale_t thread_locale = uselocale (NULL);
-    if (thread_locale != LC_GLOBAL_LOCALE)
-      localename = thread_locale->__names[category];
-    else
-      localename = "";
-  }
-#    endif
-#   endif
+  categoryname = category_to_name (category);
+#   define CATEGORYNAME_INITIALIZED
+  localename = _nl_locale_name_thread_unsafe (category, categoryname);
+  if (localename == NULL)
+    localename = "";
 #  endif
 # endif
   search.localename = localename;
@@ -677,7 +660,9 @@ DCIGETTEXT (const char *domainname, const char *msgid1, const char *msgid2,
 #endif
 
   /* Now determine the symbolic name of CATEGORY and its value.  */
+#ifndef CATEGORYNAME_INITIALIZED
   categoryname = category_to_name (category);
+#endif
 #ifdef IN_LIBGLOCALE
   categoryvalue = guess_category_value (category, categoryname, localename);
 #else
@@ -1553,20 +1538,13 @@ guess_category_value (int category, const char *categoryname)
 # ifdef _LIBC
   locale = __current_locale_name (category);
 # else
-#  if HAVE_STRUCT___LOCALE_STRUCT___NAMES && defined USE_IN_GETTEXT_TESTS
-  /* The __names field is not public glibc API and must therefore not be used
-     in code that is installed in public locations.  */
-  locale_t thread_locale = uselocale (NULL);
-  if (thread_locale != LC_GLOBAL_LOCALE)
-    {
-      locale = thread_locale->__names[category];
-      locale_defaulted = 0;
-    }
-  else
+  locale_defaulted = 0;
+#  if HAVE_USELOCALE
+  locale = _nl_locale_name_thread_unsafe (category, categoryname);
+  if (locale == NULL)
 #  endif
     {
       locale = _nl_locale_name_posix (category, categoryname);
-      locale_defaulted = 0;
       if (locale == NULL)
        {
          locale = _nl_locale_name_default ();
index 3555ede5422b77019a761ce97640a7ae17b5807f..33e68779b67289380e4c4a84d282d00cb5a7060a 100644 (file)
@@ -235,6 +235,9 @@ extern void _nl_locale_name_canonicalize (char *name);
 /* extern const char *_nl_locale_name_from_win32_LANGID (LANGID langid); */
 # define gl_locale_name_from_win32_LCID _nl_locale_name_from_win32_LCID
 /* extern const char *_nl_locale_name_from_win32_LCID (LCID lcid); */
+# define gl_locale_name_thread_unsafe _nl_locale_name_thread_unsafe
+extern const char *_nl_locale_name_thread_unsafe (int category,
+                                                 const char *categoryname);
 # define gl_locale_name_posix _nl_locale_name_posix
 extern const char *_nl_locale_name_posix (int category,
                                          const char *categoryname);
index 5e737b6ac1ba36363e5a65f1bb4d73a07d2dc51b..2bd7b9dfd1a55aeec140fcbccb116a4d65823464 100644 (file)
@@ -1,3 +1,7 @@
+2009-12-26  Bruno Haible  <bruno@clisp.org>
+
+       * intl.m4 (gt_INTL_SUBDIR_CORE): Don't check for NL_LOCALE_NAME macro.
+
 2009-12-26  Bruno Haible  <bruno@clisp.org>
 
        * intl.m4 (gt_INTL_SUBDIR_CORE): Check also for uselocale.
index f041a763db4070cdb4fcc39aa7e19d5e4d243f0a..335b23c20ceab742e8803266f7c99b0f4565d0fd 100644 (file)
@@ -1,4 +1,4 @@
-# intl.m4 serial 16 (gettext-0.18)
+# intl.m4 serial 17 (gettext-0.18)
 dnl Copyright (C) 1995-2009 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -241,22 +241,6 @@ AC_DEFUN([gt_INTL_SUBDIR_CORE],
 
   AM_ICONV
 
-  dnl glibc >= 2.4 has a NL_LOCALE_NAME macro when _GNU_SOURCE is defined,
-  dnl and a _NL_LOCALE_NAME macro always.
-  AC_CACHE_CHECK([for NL_LOCALE_NAME macro], [gt_cv_nl_locale_name],
-    [AC_TRY_LINK([#include <langinfo.h>
-#include <locale.h>],
-      [char* cs = nl_langinfo(_NL_LOCALE_NAME(LC_MESSAGES));
-       return !cs;
-      ],
-      [gt_cv_nl_locale_name=yes],
-      [gt_cv_nl_locale_name=no])
-    ])
-  if test $gt_cv_nl_locale_name = yes; then
-    AC_DEFINE([HAVE_NL_LOCALE_NAME], [1],
-      [Define if you have <langinfo.h> and it defines the NL_LOCALE_NAME macro if _GNU_SOURCE is defined.])
-  fi
-
   dnl intl/plural.c is generated from intl/plural.y. It requires bison,
   dnl because plural.y uses bison specific features. It requires at least
   dnl bison-1.26 because earlier versions generate a plural.c that doesn't
index 870920aa4ab9d29aa227e06c88a73f22e5405d09..536fe51f506cb69112cabbd14a1b9b3702cf1cbd 100644 (file)
@@ -1,3 +1,7 @@
+2009-12-26  Bruno Haible  <bruno@clisp.org>
+
+       * configure.ac: Don't define USE_IN_GETTEXT_TESTS. Test for uselocale.
+
 2009-12-12  Bruno Haible  <bruno@clisp.org>
 
        * woe32dll/export.h: Untabify.
index 711c7d47ee46245c007dda228337e92cf0ec99ae..27e0ae56701c79b8015130fdfc051c077685d638 100644 (file)
@@ -228,9 +228,6 @@ AH_TOP([
 #define DEFAULT_OUTPUT_ALIGNMENT 1
 ])
 AH_BOTTOM([
-/* Indicator for intl/ that it is compiled for testing purposes only.  */
-#define USE_IN_GETTEXT_TESTS
-
 /* A file name cannot consist of any character possible.  INVALID_PATH_CHAR
    contains the characters not allowed.  */
 #if defined _MSC_VER || defined __MINGW32__
@@ -352,7 +349,7 @@ gt_LOCALE_FR_UTF8
 gt_LOCALE_JA
 
 dnl Checks for functions for the tests/*.c tests.
-AC_CHECK_FUNCS_ONCE([getrlimit setrlimit])
+AC_CHECK_FUNCS_ONCE([getrlimit setrlimit uselocale])
 
 dnl Prepares the libtool configuration for languages used by the tests.
 LT_LANG([C++])
index dcdbba42e0ad849e66c177746ce10ca2254098b3..4ca6a394fb08e5d3d7c77dc0ac1199e6265568bd 100644 (file)
@@ -1,3 +1,26 @@
+2009-12-26  Bruno Haible  <bruno@clisp.org>
+
+       Enable the gettext-6 and gettext-7 tests also on MacOS X.
+       * Makefile.am (gettext_6_prg_CFLAGS, gettext_7_prg_CFLAGS): Depend on
+       HAVE_NEWLOCALE instead of GLIBC2.
+       (gettext_6_prg_LDADD, gettext_7_prg_LDADD): Likewise. Remove
+       libgettextlib.la.
+       * gettext-6-prg.c: Enable the test also on MacOS X platforms that have
+       uselocale.
+       (LOCALE_DE_ISO8859, LOCALE_FR_ISO8859): New macros.
+       (thread1_execution, thread2_execution): Use them.
+       (check_locale_exists): New function.
+       (main): Check for the locales if an argument is passed.
+       * gettext-7-prg.c: Enable the test also on MacOS X platforms that have
+       uselocale.
+       (LOCALE_DE_ISO8859, LOCALE_DE_UTF8): New macros.
+       (thread1_execution, thread2_execution): Use them.
+       (check_locale_exists): New function.
+       (main): Check for the locales if an argument is passed.
+       * gettext-6: Make the test work also on MacOS X systems. Test the
+       presence of the locales through the program, not through testlocale.
+       * gettext-7: Likewise.
+
 2009-12-26  Bruno Haible  <bruno@clisp.org>
 
        * gettext-7: Make the test fail when it produced unexpected results.
index 382c88c5d67cacbae76acaf93465f87faf77ead6..74dc13f5849beb317b6ca50a6162cc31b0448839 100644 (file)
@@ -221,15 +221,15 @@ gettext_4_prg_LDADD = ../gnulib-lib/libgettextlib.la $(LDADD)
 gettext_5_prg_SOURCES = gettext-5-prg.c
 gettext_5_prg_LDADD = ../gnulib-lib/libgettextlib.la $(LDADD)
 gettext_6_prg_SOURCES = gettext-6-prg.c
-gettext_6_prg_CFLAGS = $(gettext_6_prg_CFLAGS_@GLIBC2@)
-gettext_6_prg_CFLAGS_yes = -DUSE_POSIX_THREADS
-gettext_6_prg_LDADD = $(gettext_6_prg_LDADD_@GLIBC2@)
-gettext_6_prg_LDADD_yes = ../gnulib-lib/libgettextlib.la $(LDADD) -lpthread
+gettext_6_prg_CFLAGS = $(gettext_6_prg_CFLAGS_@HAVE_NEWLOCALE@)
+gettext_6_prg_CFLAGS_1 = -DUSE_POSIX_THREADS
+gettext_6_prg_LDADD = $(gettext_6_prg_LDADD_@HAVE_NEWLOCALE@)
+gettext_6_prg_LDADD_1 = $(LDADD) -lpthread
 gettext_7_prg_SOURCES = gettext-7-prg.c
-gettext_7_prg_CFLAGS = $(gettext_7_prg_CFLAGS_@GLIBC2@)
-gettext_7_prg_CFLAGS_yes = -DUSE_POSIX_THREADS
-gettext_7_prg_LDADD = $(gettext_7_prg_LDADD_@GLIBC2@)
-gettext_7_prg_LDADD_yes = ../gnulib-lib/libgettextlib.la $(LDADD) -lpthread
+gettext_7_prg_CFLAGS = $(gettext_7_prg_CFLAGS_@HAVE_NEWLOCALE@)
+gettext_7_prg_CFLAGS_1 = -DUSE_POSIX_THREADS
+gettext_7_prg_LDADD = $(gettext_7_prg_LDADD_@HAVE_NEWLOCALE@)
+gettext_7_prg_LDADD_1 = $(LDADD) -lpthread
 gettext_8_prg_SOURCES = gettext-8-prg.c
 gettext_8_prg_LDADD = ../gnulib-lib/libgettextlib.la $(LDADD)
 cake_SOURCES = plural-1-prg.c setlocale.c
index 79ba7e4695e42ffdbd72251b8f58945fd9e810b3..43b83dba242a24230d54f8e2ceee107730fddea5 100755 (executable)
@@ -7,30 +7,29 @@
 tmpfiles=""
 trap 'rm -fr $tmpfiles' 1 2 3 15
 
-# This test works only on glibc systems.
+# This test works only on glibc and MacOS X systems.
+: ${host_os=unknown}
 : ${GLIBC2=no}
-test "$GLIBC2" = yes || {
-  echo "Skipping test: not a glibc system"
+{ case "$host_os" in
+    *-gnu*) test "$GLIBC2" = yes ;;
+    darwin*) true ;;
+    *) false ;;
+  esac
+} || {
+  echo "Skipping test: not a glibc or Mac OS X system"
   exit 77
 }
 
 # This test works only on systems that have a de_DE and fr_FR locale installed.
-LC_ALL=de_DE ./testlocale || {
+missing_locale=`./gettext-6-prg 1`
+if test -n "$missing_locale"; then
   if test -f /usr/bin/localedef; then
-    echo "Skipping test: locale de_DE not installed"
+    echo "Skipping test: locale ${missing_locale} not installed"
   else
-    echo "Skipping test: locale de_DE not supported"
+    echo "Skipping test: locale ${missing_locale} not supported"
   fi
   exit 77
-}
-LC_ALL=fr_FR ./testlocale || {
-  if test -f /usr/bin/localedef; then
-    echo "Skipping test: locale fr_FR not installed"
-  else
-    echo "Skipping test: locale fr_FR not supported"
-  fi
-  exit 77
-}
+fi
 
 tmpfiles="$tmpfiles de_DE fr_FR"
 test -d de_DE || mkdir de_DE
@@ -55,7 +54,7 @@ tmpfiles="$tmpfiles gt-6.out"
 case $? in
   0) ;;
   77)
-    echo "Skipping test: not a glibc 2.3 system"
+    echo "Skipping test: not a glibc >= 2.3 or MacOS X >= 10.5 system"
     rm -fr $tmpfiles; exit 77
     ;;
 esac
index 05b4300f28ce159b28baa014a73c750689e0385d..dda514c41bc893eb7a0b4b263e36567c8489d701 100644 (file)
@@ -1,5 +1,5 @@
 /* Test program, used by the gettext-6 test.
-   Copyright (C) 2005-2007 Free Software Foundation, Inc.
+   Copyright (C) 2005-2007, 2009 Free Software Foundation, Inc.
 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -25,7 +25,7 @@
 #include <stdio.h>
 #include <string.h>
 
-#if USE_POSIX_THREADS && ((__GLIBC__ > 2) || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 3))
+#if USE_POSIX_THREADS && (__GLIBC__ >= 2 || (defined __APPLE__ && defined __MACH__)) && HAVE_USELOCALE
 
 #include <pthread.h>
 
 #undef _LIBINTL_H
 #include "libgnuintl.h"
 
+/* Name of German and French locale in ISO-8859-1 or ISO-8859-15 encoding.  */
+#if __GLIBC__ >= 2
+# define LOCALE_DE_ISO8859 "de_DE.ISO-8859-1"
+# define LOCALE_FR_ISO8859 "fr_FR.ISO-8859-1"
+#elif defined __APPLE__ && defined __MACH__ /* MacOS X */
+# define LOCALE_DE_ISO8859 "de_DE.ISO8859-1"
+# define LOCALE_FR_ISO8859 "fr_FR.ISO8859-1"
+#else
+# define LOCALE_DE_ISO8859 "de_DE"
+# define LOCALE_FR_ISO8859 "fr_FR"
+#endif
+
 /* Set to 1 if the program is not behaving correctly.  */
 int result;
 
@@ -72,7 +84,7 @@ thread1_execution (void *arg)
   char *s;
 
   waitfor (1);
-  uselocale (newlocale (LC_ALL_MASK, "de_DE", NULL));
+  uselocale (newlocale (LC_ALL_MASK, LOCALE_DE_ISO8859, NULL));
   setto (2);
 
   waitfor (1);
@@ -104,7 +116,7 @@ thread2_execution (void *arg)
   char *s;
 
   waitfor (2);
-  uselocale (newlocale (LC_ALL_MASK, "fr_FR", NULL));
+  uselocale (newlocale (LC_ALL_MASK, LOCALE_FR_ISO8859, NULL));
   setto (1);
 
   waitfor (2);
@@ -130,12 +142,36 @@ thread2_execution (void *arg)
   return NULL;
 }
 
+static void
+check_locale_exists (const char *name)
+{
+  if (newlocale (LC_ALL_MASK, name, NULL) == NULL)
+    {
+      printf ("%s\n", name);
+      exit (1);
+    }
+}
+
 int
-main (void)
+main (int argc, char *argv[])
 {
+  int arg;
   pthread_t thread1;
   pthread_t thread2;
 
+  arg = (argc > 1 ? atoi (argv[1]) : 0);
+  switch (arg)
+    {
+    case 1:
+      /* Check for the existence of the first locale.  */
+      check_locale_exists (LOCALE_DE_ISO8859);
+      /* Check for the existence of the second locale.  */
+      check_locale_exists (LOCALE_FR_ISO8859);
+      return 0;
+    default:
+      break;
+    }
+
   unsetenv ("LANGUAGE");
   unsetenv ("OUTPUT_CHARSET");
   textdomain ("tstthread");
index 5b2f502cfb23bbef8b9c653451c52938fa160a47..e97b4fc35ca5f90429fac3d092d77caf89a4551d 100755 (executable)
@@ -7,31 +7,30 @@
 tmpfiles=""
 trap 'rm -fr $tmpfiles' 1 2 3 15
 
-# This test works only on glibc systems.
+# This test works only on glibc and MacOS X systems.
+: ${host_os=unknown}
 : ${GLIBC2=no}
-test "$GLIBC2" = yes || {
-  echo "Skipping test: not a glibc system"
+{ case "$host_os" in
+    *-gnu*) test "$GLIBC2" = yes ;;
+    darwin*) true ;;
+    *) false ;;
+  esac
+} || {
+  echo "Skipping test: not a glibc or Mac OS X system"
   exit 77
 }
 
 # This test works only on systems that have a de_DE.ISO-8859-1 and
 # de_DE.UTF-8 locale installed.
-LC_ALL=de_DE.ISO-8859-1 ./testlocale || {
+missing_locale=`./gettext-7-prg 1`
+if test -n "$missing_locale"; then
   if test -f /usr/bin/localedef; then
-    echo "Skipping test: locale de_DE.ISO-8859-1 not installed"
+    echo "Skipping test: locale ${missing_locale} not installed"
   else
-    echo "Skipping test: locale de_DE.ISO-8859-1 not supported"
+    echo "Skipping test: locale ${missing_locale} not supported"
   fi
   exit 77
-}
-LC_ALL=de_DE.UTF-8 ./testlocale || {
-  if test -f /usr/bin/localedef; then
-    echo "Skipping test: locale de_DE.UTF-8 not installed"
-  else
-    echo "Skipping test: locale de_DE.UTF-8 not supported"
-  fi
-  exit 77
-}
+fi
 
 tmpfiles="$tmpfiles de_DE"
 test -d de_DE || mkdir de_DE
@@ -45,7 +44,7 @@ tmpfiles="$tmpfiles gt-7.out"
 case $? in
   0) ;;
   77)
-    echo "Skipping test: not a glibc 2.3 system"
+    echo "Skipping test: not a glibc >= 2.3 or MacOS X >= 10.5 system"
     rm -fr $tmpfiles; exit 77
     ;;
   *)
index 9ea9fc8060d82a61ac951f5232741964bf3293a8..a8e69e77eca964b4689e10ed64e489492bf2af0d 100644 (file)
@@ -1,5 +1,5 @@
 /* Test program, used by the gettext-7 test.
-   Copyright (C) 2005-2007 Free Software Foundation, Inc.
+   Copyright (C) 2005-2007, 2009 Free Software Foundation, Inc.
 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -25,7 +25,7 @@
 #include <stdio.h>
 #include <string.h>
 
-#if USE_POSIX_THREADS && ((__GLIBC__ > 2) || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 3))
+#if USE_POSIX_THREADS && (__GLIBC__ >= 2 || (defined __APPLE__ && defined __MACH__)) && HAVE_USELOCALE
 
 #include <pthread.h>
 
 #undef _LIBINTL_H
 #include "libgnuintl.h"
 
+/* Name of German locale in ISO-8859-1 or ISO-8859-15 encoding.  */
+#if __GLIBC__ >= 2
+# define LOCALE_DE_ISO8859 "de_DE.ISO-8859-1"
+#elif defined __APPLE__ && defined __MACH__ /* MacOS X */
+# define LOCALE_DE_ISO8859 "de_DE.ISO8859-1"
+#else
+# define LOCALE_DE_ISO8859 "de_DE"
+#endif
+
+/* Name of German locale in UTF-8 encoding.  */
+#define LOCALE_DE_UTF8 "de_DE.UTF-8"
+
 /* Set to 1 if the program is not behaving correctly.  */
 int result;
 
@@ -72,7 +84,7 @@ thread1_execution (void *arg)
   char *s;
 
   waitfor (1);
-  uselocale (newlocale (LC_ALL_MASK, "de_DE.ISO-8859-1", NULL));
+  uselocale (newlocale (LC_ALL_MASK, LOCALE_DE_ISO8859, NULL));
   setto (2);
 
   /* Here we expect output in ISO-8859-1.  */
@@ -106,7 +118,7 @@ thread2_execution (void *arg)
   char *s;
 
   waitfor (2);
-  uselocale (newlocale (LC_ALL_MASK, "de_DE.UTF-8", NULL));
+  uselocale (newlocale (LC_ALL_MASK, LOCALE_DE_UTF8, NULL));
   setto (1);
 
   /* Here we expect output in UTF-8.  */
@@ -134,12 +146,36 @@ thread2_execution (void *arg)
   return NULL;
 }
 
+static void
+check_locale_exists (const char *name)
+{
+  if (newlocale (LC_ALL_MASK, name, NULL) == NULL)
+    {
+      printf ("%s\n", name);
+      exit (1);
+    }
+}
+
 int
-main (void)
+main (int argc, char *argv[])
 {
+  int arg;
   pthread_t thread1;
   pthread_t thread2;
 
+  arg = (argc > 1 ? atoi (argv[1]) : 0);
+  switch (arg)
+    {
+    case 1:
+      /* Check for the existence of the first locale.  */
+      check_locale_exists (LOCALE_DE_ISO8859);
+      /* Check for the existence of the second locale.  */
+      check_locale_exists (LOCALE_DE_UTF8);
+      return 0;
+    default:
+      break;
+    }
+
   unsetenv ("LANGUAGE");
   unsetenv ("OUTPUT_CHARSET");
   textdomain ("tstthread");