summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog13
-rw-r--r--doc/posix-headers/monetary.texi2
-rw-r--r--lib/monetary.in.h105
-rw-r--r--m4/monetary_h.m465
-rw-r--r--modules/duplocale-tests2
-rw-r--r--modules/monetary57
-rw-r--r--modules/monetary-c++-tests18
-rw-r--r--modules/monetary-tests10
-rw-r--r--tests/test-monetary-c++.cc39
-rw-r--r--tests/test-monetary.c29
10 files changed, 338 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index be1f9f8df4..2b88ede19e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,18 @@
2017-09-23 Bruno Haible <bruno@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 <bruno@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 834bf524f5..27ad38e4cd 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 0000000000..52966c44d4
--- /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 0000000000..3ef6a0b004
--- /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 3420abf5de..baa9a63102 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 0000000000..c8be360018
--- /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 0000000000..bd4d52e81c
--- /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 0000000000..eedd0a1e82
--- /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 0000000000..6b3079a616
--- /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 <bruno@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 0000000000..c1f01fc9ce
--- /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 <bruno@clisp.org>, 2017. */
+
+#include <config.h>
+
+#if HAVE_MONETARY_H
+# include <monetary.h>
+#endif
+
+int
+main ()
+{
+ return 0;
+}