Hello Tom,

> The duplocale test is failling on CentOS 6:
> 
> test-duplocale.c:187: assertion 'strcmp (results.monetary, 
> expected_results.monetary) == 0' failed
> 
> I ran it under gdb to see the values:
> (gdb) run
> Starting program: 
> /home/tgc/projects/gnulib/duplocale/gltests/test-duplocale
> 
> Breakpoint 1, test_with_locale_parameter () at test-duplocale.c:187
> 187         ASSERT (strcmp (results.monetary, expected_results.monetary) == 
> 0);
> Missing separate debuginfos, use: debuginfo-install 
> glibc-2.12-1.209.el6_9.2.x86_64
> (gdb) p results.monetary
> $1 = 
> "$123,75\000\202\254\000\377\377\177\000\000\001\000\000\000\000\000\000\000H\347\377\367\377\177\000\000\177U\335q\000\000\000\000\226V\336\367\377\177",
>  
> '\000' <repeats 11 times>"\336, 
> \377\377\377\177\000\000?\000\000\000\000\000\000\000\000\336\377\377\377\177\000\000\003\000\000\000\063,5\000P\253\377\367\377\177\000\000.N="
> (gdb) p expected_results.monetary
> $2 = 
> "$123.75\000\350\344\377\367\377\177\000\000\320\337\377\377\377\177\000\000\370\337\377\377\377\177\000\000\220\341\377\367\377\177\000\000\230\253\377\367\377\177\000\000.N=\366\000\000\000\000jb\336\367\377\177\000\000\000\000\000\000\000\000\000\000\230\253\377\367\377\177\000\000\001\000\000\000\063,5\000\000\000\000\000\000\000\000\000\001\000\000"
> 
> Ignoring the garbage you can see a comma where the dot was expected.

Thanks for the report. This assertion failure is a combination of
  (1) a bug in the test: it was freeing a locale object that was still in use as
      the current thread's locale,
  (2) glibc bug <https://sourceware.org/bugzilla/show_bug.cgi?id=19633>
      which produces a dot instead of a comma or vice versa.

I could reproduce (1) as a crash inside nl_langinfo() on glibc/x86 systems
(but not on glibc/x86_64 systems), even on systems with glibc-2.24, where (2)
is already fixed.

And once I fixed (1), I could no longer reproduce the test failure you reported.
But another test program, written specifically for (2), still failed.

So I've committed:
  - for (1): a test fix.
  - for (2): new modules 'monetary' and 'strfmon_l'.

Thanks for this report!

Bruno
>From 96335dc0af877d7d4e5353c3c7c509b930b1df98 Mon Sep 17 00:00:00 2001
From: Bruno Haible <br...@clisp.org>
Date: Sat, 23 Sep 2017 16:01:33 +0200
Subject: [PATCH 1/3] duplocale tests: Fix test crash on Linux/x86.

* tests/test-duplocale.c (test_with_uselocale): Disconnect the mixed2
locale from the current thread before freeing it.
---
 ChangeLog              | 6 ++++++
 tests/test-duplocale.c | 1 +
 2 files changed, 7 insertions(+)

diff --git a/ChangeLog b/ChangeLog
index 82ecf53..be1f9f8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2017-09-23  Bruno Haible  <br...@clisp.org>
+
+	duplocale tests: Fix test crash on Linux/x86.
+	* tests/test-duplocale.c (test_with_uselocale): Disconnect the mixed2
+	locale from the current thread before freeing it.
+
 2017-09-21  Paul Eggert  <egg...@cs.ucla.edu>
 
 	mktime: port to OpenVMS
diff --git a/tests/test-duplocale.c b/tests/test-duplocale.c
index 49ff0ff..9b2c4cf 100644
--- a/tests/test-duplocale.c
+++ b/tests/test-duplocale.c
@@ -115,6 +115,7 @@ test_with_uselocale (void)
   }
 
   setlocale (LC_ALL, "C");
+  uselocale (LC_GLOBAL_LOCALE);
   freelocale (mixed1);
   freelocale (mixed2);
   freelocale (perthread);
-- 
2.7.4

>From b2fc4a431927a6fbdd523bef93357134d9c489a9 Mon Sep 17 00:00:00 2001
From: Bruno Haible <br...@clisp.org>
Date: Sat, 23 Sep 2017 09:26:48 +0200
Subject: [PATCH 2/3] monetary: New module.

* modules/monetary: New file.
* lib/monetary.in.h: New file.
* m4/monetary_h.m4: New file.
* doc/posix-headers/monetary.texi: Mention the new module.
* modules/monetary-tests: New file.
* tests/test-monetary.c: New file.
* modules/monetary-c++-tests: New file.
* tests/test-monetary-c++.cc: New file.
* modules/duplocale-tests (configure.ac): Use AC_CHECK_HEADERS_ONCE.
---
 ChangeLog                       |  13 +++++
 doc/posix-headers/monetary.texi |   2 +-
 lib/monetary.in.h               | 105 ++++++++++++++++++++++++++++++++++++++++
 m4/monetary_h.m4                |  65 +++++++++++++++++++++++++
 modules/duplocale-tests         |   2 +-
 modules/monetary                |  57 ++++++++++++++++++++++
 modules/monetary-c++-tests      |  18 +++++++
 modules/monetary-tests          |  10 ++++
 tests/test-monetary-c++.cc      |  39 +++++++++++++++
 tests/test-monetary.c           |  29 +++++++++++
 10 files changed, 338 insertions(+), 2 deletions(-)
 create mode 100644 lib/monetary.in.h
 create mode 100644 m4/monetary_h.m4
 create mode 100644 modules/monetary
 create mode 100644 modules/monetary-c++-tests
 create mode 100644 modules/monetary-tests
 create mode 100644 tests/test-monetary-c++.cc
 create mode 100644 tests/test-monetary.c

diff --git a/ChangeLog b/ChangeLog
index be1f9f8..2b88ede 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,18 @@
 2017-09-23  Bruno Haible  <br...@clisp.org>
 
+	monetary: New module.
+	* modules/monetary: New file.
+	* lib/monetary.in.h: New file.
+	* m4/monetary_h.m4: New file.
+	* doc/posix-headers/monetary.texi: Mention the new module.
+	* modules/monetary-tests: New file.
+	* tests/test-monetary.c: New file.
+	* modules/monetary-c++-tests: New file.
+	* tests/test-monetary-c++.cc: New file.
+	* modules/duplocale-tests (configure.ac): Use AC_CHECK_HEADERS_ONCE.
+
+2017-09-23  Bruno Haible  <br...@clisp.org>
+
 	duplocale tests: Fix test crash on Linux/x86.
 	* tests/test-duplocale.c (test_with_uselocale): Disconnect the mixed2
 	locale from the current thread before freeing it.
diff --git a/doc/posix-headers/monetary.texi b/doc/posix-headers/monetary.texi
index 834bf52..27ad38e 100644
--- a/doc/posix-headers/monetary.texi
+++ b/doc/posix-headers/monetary.texi
@@ -3,7 +3,7 @@
 
 POSIX specification:@* @url{http://www.opengroup.org/onlinepubs/9699919799/basedefs/monetary.h.html}
 
-Gnulib module: ---
+Gnulib module: monetary
 
 Portability problems fixed by Gnulib:
 @itemize
diff --git a/lib/monetary.in.h b/lib/monetary.in.h
new file mode 100644
index 0000000..52966c4
--- /dev/null
+++ b/lib/monetary.in.h
@@ -0,0 +1,105 @@
+/* Wrapper around <monetary.h>.
+   Copyright (C) 2017 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
+   the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, see <https://www.gnu.org/licenses/>.  */
+
+#ifndef _@GUARD_PREFIX@_MONETARY_H
+
+#if __GNUC__ >= 3
+@PRAGMA_SYSTEM_HEADER@
+#endif
+@PRAGMA_COLUMNS@
+
+/* The include_next requires a split double-inclusion guard.  */
+#if @HAVE_MONETARY_H@
+# @INCLUDE_NEXT@ @NEXT_MONETARY_H@
+#endif
+
+#ifndef _@GUARD_PREFIX@_MONETARY_H
+#define _@GUARD_PREFIX@_MONETARY_H
+
+#if @GNULIB_STRFMON_L@ && @HAVE_XLOCALE_H@
+/* Get locale_t on Mac OS X 10.12.  */
+# include <xlocale.h>
+#endif
+
+/* Like in <stdio.h>.  */
+#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7)
+# define _GL_ATTRIBUTE_FORMAT(spec) __attribute__ ((__format__ spec))
+#else
+# define _GL_ATTRIBUTE_FORMAT(spec) /* empty */
+#endif
+
+/* _GL_ATTRIBUTE_FORMAT_STRFMON
+   indicates to GCC that the function takes a format string and arguments,
+   where the format string directives are the ones standardized by ISO C99
+   and POSIX.  */
+#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4)
+# define _GL_ATTRIBUTE_FORMAT_STRFMON(formatstring_parameter, first_argument) \
+   _GL_ATTRIBUTE_FORMAT ((__gnu_strfmon__, formatstring_parameter, first_argument))
+#elif __GNUC__ >= 3
+# define _GL_ATTRIBUTE_FORMAT_STRFMON(formatstring_parameter, first_argument) \
+   _GL_ATTRIBUTE_FORMAT ((__strfmon__, formatstring_parameter, first_argument))
+#else
+# define _GL_ATTRIBUTE_FORMAT_STRFMON(formatstring_parameter, first_argument) /* empty */
+#endif
+
+
+/* The definitions of _GL_FUNCDECL_RPL etc. are copied here.  */
+
+/* The definition of _GL_ARG_NONNULL is copied here.  */
+
+/* The definition of _GL_WARN_ON_USE is copied here.  */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+#if @GNULIB_STRFMON_L@
+/* Converts a monetary value to a string.
+   See the POSIX:2008 specification
+   <http://pubs.opengroup.org/onlinepubs/9699919799/functions/strfmon_l.html.  */
+# if @REPLACE_STRFMON_L@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   define strfmon_l rpl_strfmon_l
+#  endif
+_GL_FUNCDECL_RPL (strfmon_l, ssize_t, (char *s, size_t maxsize, locale_t locale,
+                                       const char *format, ...)
+                                      _GL_ATTRIBUTE_FORMAT_STRFMON (4, 5)
+                                      _GL_ARG_NONNULL ((4)));
+_GL_CXXALIAS_RPL (strfmon_l, ssize_t, (char *s, size_t maxsize, locale_t locale,
+                                       const char *format, ...));
+# else
+#  if @HAVE_STRFMON_L@
+_GL_CXXALIAS_SYS (strfmon_l, ssize_t, (char *s, size_t maxsize, locale_t locale,
+                                       const char *format, ...));
+#  endif
+# endif
+_GL_CXXALIASWARN (strfmon_l);
+#elif defined GNULIB_POSIXCHECK
+# undef strfmon_l
+# if HAVE_RAW_DECL_STRFMON_L
+_GL_WARN_ON_USE (strfmon_l, "strfmon_l is buggy on older glibc systems - "
+                 "use gnulib module chown for portability");
+# endif
+#endif
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _@GUARD_PREFIX@_MONETARY_H */
+#endif /* _@GUARD_PREFIX@_MONETARY_H */
diff --git a/m4/monetary_h.m4 b/m4/monetary_h.m4
new file mode 100644
index 0000000..3ef6a0b
--- /dev/null
+++ b/m4/monetary_h.m4
@@ -0,0 +1,65 @@
+# monetary_h.m4 serial 1
+dnl Copyright (C) 2017 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+AC_DEFUN([gl_MONETARY_H],
+[
+  dnl Use AC_REQUIRE here, so that the default behavior below is expanded
+  dnl once only, before all statements that occur in other macros.
+  AC_REQUIRE([gl_MONETARY_H_BODY])
+])
+
+AC_DEFUN([gl_MONETARY_H_BODY],
+[
+  AC_REQUIRE([gl_MONETARY_H_DEFAULTS])
+
+  AC_CHECK_HEADERS_ONCE([monetary.h])
+  dnl For now, we provide a <monetary.h> wrapper only if the system already
+  dnl has a <monetary.h>.
+  if test $ac_cv_header_monetary_h = yes; then
+    MONETARY_H='monetary.h'
+
+    gl_CHECK_NEXT_HEADERS([monetary.h])
+    if test $ac_cv_header_monetary_h = yes; then
+      HAVE_MONETARY_H=1
+    else
+      HAVE_MONETARY_H=0
+    fi
+    AC_SUBST([HAVE_MONETARY_H])
+
+    AC_CHECK_HEADERS_ONCE([xlocale.h])
+    if test $ac_cv_header_xlocale_h = yes; then
+      HAVE_XLOCALE_H=1
+    else
+      HAVE_XLOCALE_H=0
+    fi
+    AC_SUBST([HAVE_XLOCALE_H])
+
+    dnl Check for declarations of anything we want to poison if the
+    dnl corresponding gnulib module is not in use.
+    gl_WARN_ON_USE_PREPARE([[
+      #include <monetary.h>
+      ]], [strfmon_l])
+  else
+    MONETARY_H=''
+  fi
+  AC_SUBST([MONETARY_H])
+  AM_CONDITIONAL([GL_GENERATE_MONETARY_H], [test -n "$MONETARY_H"])
+])
+
+AC_DEFUN([gl_MONETARY_MODULE_INDICATOR],
+[
+  dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
+  AC_REQUIRE([gl_MONETARY_H_DEFAULTS])
+  gl_MODULE_INDICATOR_SET_VARIABLE([$1])
+])
+
+AC_DEFUN([gl_MONETARY_H_DEFAULTS],
+[
+  GNULIB_STRFMON_L=0;      AC_SUBST([GNULIB_STRFMON_L])
+  dnl Assume proper GNU behavior unless another module says otherwise.
+  HAVE_STRFMON_L=1;        AC_SUBST([HAVE_STRFMON_L])
+  REPLACE_STRFMON_L=0;     AC_SUBST([REPLACE_STRFMON_L])
+])
diff --git a/modules/duplocale-tests b/modules/duplocale-tests
index 3420abf..baa9a63 100644
--- a/modules/duplocale-tests
+++ b/modules/duplocale-tests
@@ -8,7 +8,7 @@ langinfo
 
 configure.ac:
 AC_CHECK_FUNCS_ONCE([duplocale uselocale strfmon_l snprintf_l nl_langinfo_l])
-AC_CHECK_HEADERS([monetary.h])
+AC_CHECK_HEADERS_ONCE([monetary.h])
 
 Makefile.am:
 TESTS += test-duplocale
diff --git a/modules/monetary b/modules/monetary
new file mode 100644
index 0000000..c8be360
--- /dev/null
+++ b/modules/monetary
@@ -0,0 +1,57 @@
+Description:
+A substitute <monetary.h>.
+
+Files:
+lib/monetary.in.h
+m4/monetary_h.m4
+
+Depends-on:
+include_next
+snippet/arg-nonnull
+snippet/c++defs
+snippet/warn-on-use
+
+configure.ac:
+gl_MONETARY_H
+
+Makefile.am:
+BUILT_SOURCES += $(MONETARY_H)
+
+# We need the following in order to create <monetary.h> when the system
+# doesn't have one that works with the given compiler.
+if GL_GENERATE_MONETARY_H
+monetary.h: monetary.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(WARN_ON_USE_H) $(ARG_NONNULL_H)
+	$(AM_V_GEN)rm -f $@-t $@ && \
+	{ echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */' && \
+	  sed -e 's|@''GUARD_PREFIX''@|${gl_include_guard_prefix}|g' \
+	      -e 's|@''HAVE_MONETARY_H''@|$(HAVE_MONETARY_H)|g' \
+	      -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
+	      -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
+	      -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
+	      -e 's|@''NEXT_MONETARY_H''@|$(NEXT_MONETARY_H)|g' \
+	      -e 's|@''HAVE_XLOCALE_H''@|$(HAVE_XLOCALE_H)|g' \
+	      -e 's|@''GNULIB_STRFMON_L''@|$(GNULIB_STRFMON_L)|g' \
+	      -e 's|@''HAVE_STRFMON_L''@|$(HAVE_STRFMON_L)|g' \
+	      -e 's|@''REPLACE_STRFMON_L''@|$(REPLACE_STRFMON_L)|g' \
+	      -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \
+	      -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \
+	      -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \
+	      < $(srcdir)/monetary.in.h; \
+	} > $@-t && \
+	mv $@-t $@
+else
+monetary.h: $(top_builddir)/config.status
+	rm -f $@
+endif
+MOSTLYCLEANFILES += monetary.h monetary.h-t
+
+Include:
+#if HAVE_MONETARY_H
+<monetary.h>
+#endif
+
+License:
+LGPLv2+
+
+Maintainer:
+all
diff --git a/modules/monetary-c++-tests b/modules/monetary-c++-tests
new file mode 100644
index 0000000..bd4d52e
--- /dev/null
+++ b/modules/monetary-c++-tests
@@ -0,0 +1,18 @@
+Files:
+tests/test-monetary-c++.cc
+tests/signature.h
+
+Status:
+c++-test
+
+Depends-on:
+ansi-c++-opt
+
+configure.ac:
+
+Makefile.am:
+if ANSICXX
+TESTS += test-monetary-c++
+check_PROGRAMS += test-monetary-c++
+test_monetary_c___SOURCES = test-monetary-c++.cc
+endif
diff --git a/modules/monetary-tests b/modules/monetary-tests
new file mode 100644
index 0000000..eedd0a1
--- /dev/null
+++ b/modules/monetary-tests
@@ -0,0 +1,10 @@
+Files:
+tests/test-monetary.c
+
+Depends-on:
+
+configure.ac:
+
+Makefile.am:
+TESTS += test-monetary
+check_PROGRAMS += test-monetary
diff --git a/tests/test-monetary-c++.cc b/tests/test-monetary-c++.cc
new file mode 100644
index 0000000..6b3079a
--- /dev/null
+++ b/tests/test-monetary-c++.cc
@@ -0,0 +1,39 @@
+/* Test of <monetary.h> substitute in C++ mode.
+   Copyright (C) 2017 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
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
+
+/* Written by Bruno Haible <br...@clisp.org>, 2017.  */
+
+#define GNULIB_NAMESPACE gnulib
+#include <config.h>
+
+#if HAVE_MONETARY_H
+# include <monetary.h>
+#endif
+
+#include "signature.h"
+
+
+#if GNULIB_TEST_STRFMON_L
+SIGNATURE_CHECK (GNULIB_NAMESPACE::strfmon_l, ssize_t,
+                 (char *s, size_t maxsize, locale_t locale,
+                  const char *format, ...));
+#endif
+
+
+int
+main ()
+{
+}
diff --git a/tests/test-monetary.c b/tests/test-monetary.c
new file mode 100644
index 0000000..c1f01fc
--- /dev/null
+++ b/tests/test-monetary.c
@@ -0,0 +1,29 @@
+/* Test of <monetary.h> substitute.
+   Copyright (C) 2017 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
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
+
+/* Written by Bruno Haible <br...@clisp.org>, 2017.  */
+
+#include <config.h>
+
+#if HAVE_MONETARY_H
+# include <monetary.h>
+#endif
+
+int
+main ()
+{
+  return 0;
+}
-- 
2.7.4

>From 19882ec15628386c45977ade98293e26791b7a15 Mon Sep 17 00:00:00 2001
From: Bruno Haible <br...@clisp.org>
Date: Sat, 23 Sep 2017 12:22:17 +0200
Subject: [PATCH 3/3] strfmon_l: New module.

* modules/strfmon_l: New file.
* lib/strfmon_l.c: New file.
* m4/strfmon_l.m4: New file.
* doc/posix-functions/strfmon_l.texi: Mention the new module.
* modules/strfmon_l-tests: New file.
* tests/test-strfmon_l.c: New file.
---
 ChangeLog                          |  8 ++++
 doc/posix-functions/strfmon_l.texi |  5 +-
 lib/strfmon_l.c                    | 64 ++++++++++++++++++++++++++
 m4/strfmon_l.m4                    | 46 +++++++++++++++++++
 modules/strfmon_l                  | 31 +++++++++++++
 modules/strfmon_l-tests            | 12 +++++
 tests/test-strfmon_l.c             | 93 ++++++++++++++++++++++++++++++++++++++
 7 files changed, 258 insertions(+), 1 deletion(-)
 create mode 100644 lib/strfmon_l.c
 create mode 100644 m4/strfmon_l.m4
 create mode 100644 modules/strfmon_l
 create mode 100644 modules/strfmon_l-tests
 create mode 100644 tests/test-strfmon_l.c

diff --git a/ChangeLog b/ChangeLog
index 2b88ede..a317d01 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
 2017-09-23  Bruno Haible  <br...@clisp.org>
 
+	strfmon_l: New module.
+	* modules/strfmon_l: New file.
+	* lib/strfmon_l.c: New file.
+	* m4/strfmon_l.m4: New file.
+	* doc/posix-functions/strfmon_l.texi: Mention the new module.
+	* modules/strfmon_l-tests: New file.
+	* tests/test-strfmon_l.c: New file.
+
 	monetary: New module.
 	* modules/monetary: New file.
 	* lib/monetary.in.h: New file.
diff --git a/doc/posix-functions/strfmon_l.texi b/doc/posix-functions/strfmon_l.texi
index b9da883..754dd1d 100644
--- a/doc/posix-functions/strfmon_l.texi
+++ b/doc/posix-functions/strfmon_l.texi
@@ -4,10 +4,13 @@
 
 POSIX specification:@* @url{http://www.opengroup.org/onlinepubs/9699919799/functions/strfmon_l.html}
 
-Gnulib module: ---
+Gnulib module: strfmon_l
 
 Portability problems fixed by Gnulib:
 @itemize
+@item
+This function uses a wrong locale for the numbers on some platforms:
+glibc 2.23.
 @end itemize
 
 Portability problems not fixed by Gnulib:
diff --git a/lib/strfmon_l.c b/lib/strfmon_l.c
new file mode 100644
index 0000000..ac80d65
--- /dev/null
+++ b/lib/strfmon_l.c
@@ -0,0 +1,64 @@
+/* strfmon_l override.
+   Copyright (C) 2017 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
+   the Free Software Foundation; either version 3, or (at your option)
+   any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License along
+   with this program; if not, see <https://www.gnu.org/licenses/>.  */
+
+#include <config.h>
+
+/* Specification.  */
+#include <monetary.h>
+
+#include <locale.h>
+#include <stdarg.h>
+
+#undef strfmon_l
+
+/* This override can only support a limited number of arguments.  */
+#define MAX_ARG_WORDS 16
+
+ssize_t
+rpl_strfmon_l (char *s, size_t maxsize, locale_t locale, const char *format, ...)
+{
+  /* Work around glibc 2.23 bug
+     <https://sourceware.org/bugzilla/show_bug.cgi?id=19633>.  */
+  va_list argptr;
+  double args[MAX_ARG_WORDS];
+  int i;
+  locale_t orig_locale;
+  ssize_t result;
+
+  orig_locale = uselocale ((locale_t)0);
+
+  if (uselocale (locale) == (locale_t)0)
+    /* errno is set.  */
+    return -1;
+
+  va_start (argptr, format);
+  /* Hack: Consume more arguments than those that are actually given.  */
+  for (i = 0; i < MAX_ARG_WORDS; i++)
+    args[i] = va_arg (argptr, double);
+
+  result = strfmon_l (s, maxsize, locale, format,
+                      args[0], args[1], args[2], args[3], args[4], args[5],
+                      args[6], args[7], args[8], args[9], args[10], args[11],
+                      args[12], args[13], args[14], args[15]);
+
+  va_end (argptr);
+
+  if (uselocale (orig_locale) == (locale_t)0)
+    /* errno is set.  */
+    return -1;
+
+  return result;
+}
diff --git a/m4/strfmon_l.m4 b/m4/strfmon_l.m4
new file mode 100644
index 0000000..d6dd48a
--- /dev/null
+++ b/m4/strfmon_l.m4
@@ -0,0 +1,46 @@
+# strfmon_l.m4 serial 1
+dnl Copyright (C) 2017 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+AC_DEFUN([gl_FUNC_STRFMON_L],
+[
+  AC_REQUIRE([gl_MONETARY_H_DEFAULTS])
+
+  dnl Persuade glibc <monetary.h> to declare strfmon_l().
+  AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
+  dnl On Mac OS X 10.12, <monetary.h> may declare strfmon_l() if
+  dnl _USE_EXTENDED_LOCALES_ is defined. But this symbol is supposed
+  dnl to be defined by <xlocale.h>, not by us.
+
+  AC_CHECK_FUNCS_ONCE([strfmon_l])
+  if test $ac_cv_func_strfmon_l = yes; then
+    dnl Test for bug <https://sourceware.org/bugzilla/show_bug.cgi?id=19633>
+    dnl which was fixed in glibc-2.24.
+    AC_CACHE_CHECK([whether strfmon_l works],
+      [gl_cv_strfmon_l_works],
+      [AC_EGREP_CPP([Unlucky],
+         [
+#include <features.h>
+#ifdef __GNU_LIBRARY__
+ #if (__GLIBC__ == 2 && __GLIBC_MINOR__ < 24)
+  Unlucky GNU user
+ #endif
+#endif
+         ],
+         [gl_cv_strfmon_l_works=no],
+         [gl_cv_strfmon_l_works="guessing yes"])
+      ])
+    if test "$gl_cv_strfmon_l_works" = no; then
+      REPLACE_STRFMON_L=1
+    fi
+  else
+    HAVE_STRFMON_L=0
+  fi
+])
+
+# Prerequisites of lib/strfmon_l.c.
+AC_DEFUN([gl_PREREQ_STRFMON_L], [
+  :
+])
diff --git a/modules/strfmon_l b/modules/strfmon_l
new file mode 100644
index 0000000..42a4c96
--- /dev/null
+++ b/modules/strfmon_l
@@ -0,0 +1,31 @@
+Description:
+strfmon_l() function: formatted conversion of monetary value to string.
+
+Files:
+lib/strfmon_l.c
+m4/strfmon_l.m4
+
+Depends-on:
+monetary
+extensions
+
+configure.ac:
+gl_FUNC_STRFMON_L
+if test $REPLACE_STRFMON_L = 1; then
+  AC_LIBOBJ([strfmon_l])
+  gl_PREREQ_STRFMON_L
+fi
+gl_MONETARY_MODULE_INDICATOR([strfmon_l])
+
+Makefile.am:
+
+Include:
+#if HAVE_MONETARY_H
+<monetary.h>
+#endif
+
+License:
+LGPLv2+
+
+Maintainer:
+all
diff --git a/modules/strfmon_l-tests b/modules/strfmon_l-tests
new file mode 100644
index 0000000..871962c
--- /dev/null
+++ b/modules/strfmon_l-tests
@@ -0,0 +1,12 @@
+Files:
+tests/test-strfmon_l.c
+tests/signature.h
+tests/macros.h
+
+Depends-on:
+
+configure.ac:
+
+Makefile.am:
+TESTS += test-strfmon_l
+check_PROGRAMS += test-strfmon_l
diff --git a/tests/test-strfmon_l.c b/tests/test-strfmon_l.c
new file mode 100644
index 0000000..4605c8d
--- /dev/null
+++ b/tests/test-strfmon_l.c
@@ -0,0 +1,93 @@
+/*
+ * Copyright (C) 2017 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
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
+
+#include <config.h>
+
+#if HAVE_MONETARY_H
+# include <monetary.h>
+#endif
+
+#include "signature.h"
+#if HAVE_STRFMON_L
+SIGNATURE_CHECK (strfmon_l, ssize_t, (char *s, size_t maxsize, locale_t locale,
+                                      const char *format, ...));
+#endif
+
+#include <locale.h>
+#include <stdio.h>
+#include <string.h>
+
+#include "macros.h"
+
+int
+main (void)
+{
+#if HAVE_STRFMON_L
+  /* Simple test in the C locale.  */
+  {
+    char buf[80];
+    locale_t loc;
+    ssize_t ret;
+
+    loc = newlocale (LC_ALL_MASK, "C", NULL);
+    ASSERT (loc != NULL);
+    ret = strfmon_l (buf, sizeof (buf), loc, "%^#5.0n", 123.4);
+    ASSERT (   (ret == 5 && strcmp (buf,  "  123") == 0) /* AIX, Solaris */
+            || (ret == 6 && strcmp (buf, "   123") == 0) /* glibc */
+            || (ret == 7 && strcmp (buf, "   123 ") == 0) /* Mac OS X */
+           );
+  }
+
+  /* Test whether the decimal point comes from the right locale:
+     glibc bug <https://sourceware.org/bugzilla/show_bug.cgi?id=19633>.  */
+  if (setlocale (LC_ALL, "en_US.UTF-8") == NULL)
+    {
+      fprintf (stderr, "Skipping test: English Unicode locale is not installed\n");
+      return 77;
+    }
+  if (setlocale (LC_ALL, "de_DE.UTF-8") == NULL)
+    {
+      fprintf (stderr, "Skipping test: English Unicode locale is not installed\n");
+      return 77;
+    }
+  {
+    char expected_buf[80];
+    locale_t loc;
+    char buf[80];
+
+    setlocale (LC_ALL, "en_US.UTF-8");
+    ASSERT (strfmon (expected_buf, sizeof (expected_buf), "%.2n", 123.5) >= 0);
+    setlocale (LC_ALL, "de_DE.UTF-8");
+    loc = newlocale (LC_ALL_MASK, "en_US.UTF-8", NULL);
+    ASSERT (strfmon_l (buf, sizeof (buf), loc, "%.2n", 123.5) >= 0);
+    ASSERT (strcmp (buf, expected_buf) == 0);
+  }
+  {
+    char expected_buf[80];
+    locale_t loc;
+    char buf[80];
+
+    setlocale (LC_ALL, "de_DE.UTF-8");
+    ASSERT (strfmon (expected_buf, sizeof (expected_buf), "%.2n", 123.5) >= 0);
+    setlocale (LC_ALL, "en_US.UTF-8");
+    loc = newlocale (LC_ALL_MASK, "de_DE.UTF-8", NULL);
+    ASSERT (strfmon_l (buf, sizeof (buf), loc, "%.2n", 123.5) >= 0);
+    ASSERT (strcmp (buf, expected_buf) == 0);
+  }
+#endif
+
+  return 0;
+}
-- 
2.7.4

Reply via email to