changeset 12340:2da64958ab60

locale: Make locale_t available when possible.
author Bruno Haible <bruno@clisp.org>
date Sun, 22 Nov 2009 23:31:11 +0100
parents ec411e51b85a
children f7a07cd4228a
files ChangeLog doc/posix-headers/locale.texi lib/locale.in.h m4/locale_h.m4 modules/locale
diffstat 5 files changed, 59 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2009-11-22  Bruno Haible  <bruno@clisp.org>
+
+	locale: Make locale_t available when possible.
+	* lib/locale.in.h: Include <xlocale.h> when it exists.
+	* m4/locale_h.m4 (gl_LOCALE_H): Check for <xlocale.h> and arrange to
+	replace <locale.h> if it does not define locale_t but <xlocale.h> does.
+	* modules/locale (Depends-on): Add extensions.
+	(Makefile.am): Also substitute HAVE_XLOCALE_H.
+	* doc/posix-headers/locale.texi: Document the problem with locale_t.
+
 2009-11-22  Bruno Haible  <bruno@clisp.org>
 
 	Add comments.
--- a/doc/posix-headers/locale.texi
+++ b/doc/posix-headers/locale.texi
@@ -12,6 +12,10 @@
 mingw.
 
 @item
+The @code{locale_t} type is not defined on some platforms:
+glibc 2.11, MacOS X 10.5.
+
+@item
 Some platforms provide a @code{NULL} macro that cannot be used in arbitrary
 expressions:
 NetBSD 5.0
--- a/lib/locale.in.h
+++ b/lib/locale.in.h
@@ -29,6 +29,11 @@
 /* NetBSD 5.0 mis-defines NULL.  */
 #include <stddef.h>
 
+/* MacOS X 10.5 defines the locale_t type in <xlocale.h>.  */
+#if @HAVE_XLOCALE_H@
+# include <xlocale.h>
+#endif
+
 /* The LC_MESSAGES locale category is specified in POSIX, but not in ISO C.
    On systems that don't define it, use the same value as GNU libintl.  */
 #if !defined LC_MESSAGES
--- a/m4/locale_h.m4
+++ b/m4/locale_h.m4
@@ -1,4 +1,4 @@
-# locale_h.m4 serial 3
+# locale_h.m4 serial 4
 dnl Copyright (C) 2007, 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,
@@ -6,17 +6,47 @@
 
 AC_DEFUN([gl_LOCALE_H],
 [
-  AC_CACHE_CHECK([whether locale.h conforms to POSIX],
-    [gl_cv_header_working_locale_h],
-    [AC_TRY_COMPILE([#include <locale.h>
-int x = LC_MESSAGES;], [],
-       [gl_cv_header_working_locale_h=yes],
-       [gl_cv_header_working_locale_h=no])])
+  dnl Persuade glibc <locale.h> to define locale_t.
+  AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
 
   dnl If <stddef.h> is replaced, then <locale.h> must also be replaced.
   AC_REQUIRE([gl_STDDEF_H])
 
-  if test $gl_cv_header_working_locale_h = yes && test -z "$STDDEF_H"; then
+  AC_CACHE_CHECK([whether locale.h conforms to POSIX:2001],
+    [gl_cv_header_locale_h_posix2001],
+    [AC_TRY_COMPILE([#include <locale.h>
+int x = LC_MESSAGES;], [],
+       [gl_cv_header_locale_h_posix2001=yes],
+       [gl_cv_header_locale_h_posix2001=no])])
+
+  dnl Check for <xlocale.h>.
+  AC_CHECK_HEADERS_ONCE([xlocale.h])
+  if test $ac_cv_header_xlocale_h = yes; then
+    HAVE_XLOCALE_H=1
+    dnl Check whether use of locale_t requires inclusion of <xlocale.h>,
+    dnl e.g. on MacOS X 10.5. If <locale.h> does not define locale_t by
+    dnl itself, we assume that <xlocale.h> will do so.
+    AC_CACHE_CHECK([whether locale.h defines locale_t],
+      [gl_cv_header_locale_has_locale_t],
+      [AC_TRY_COMPILE([#include <locale.h>
+locale_t x;], [],
+         [gl_cv_header_locale_has_locale_t=yes],
+         [gl_cv_header_locale_has_locale_t=no])
+      ])
+    if test $gl_cv_header_locale_has_locale_t = yes; then
+      gl_cv_header_locale_h_needs_xlocale_h=no
+    else
+      gl_cv_header_locale_h_needs_xlocale_h=yes
+    fi
+  else
+    HAVE_XLOCALE_H=0
+    gl_cv_header_locale_h_needs_xlocale_h=no
+  fi
+  AC_SUBST([HAVE_XLOCALE_H])
+
+  if test -z "$STDDEF_H" \
+     && test $gl_cv_header_locale_h_posix2001 = yes \
+     && test $gl_cv_header_locale_h_needs_xlocale_h = no; then
     LOCALE_H=
   else
     gl_CHECK_NEXT_HEADERS([locale.h])
--- a/modules/locale
+++ b/modules/locale
@@ -7,6 +7,7 @@
 
 Depends-on:
 include_next
+extensions
 stddef
 
 configure.ac:
@@ -23,6 +24,7 @@
 	  sed -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
 	      -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
 	      -e 's|@''NEXT_LOCALE_H''@|$(NEXT_LOCALE_H)|g' \
+	      -e 's|@''HAVE_XLOCALE_H''@|$(HAVE_XLOCALE_H)|g' \
 	      < $(srcdir)/locale.in.h; \
 	} > $@-t && \
 	mv $@-t $@