This patch series implements new modules
dprintf -> vdzprintf
dzprintf -> vasnprintf
vdprintf -> vdzprintf
vdzprintf -> vasnprintf
and the -posix and -gnu variants that go with them.
2024-06-30 Bruno Haible <[email protected]>
dzprintf-gnu: Add tests.
* tests/test-dprintf-gnu.h: New file, extracted from
tests/test-dprintf-gnu.c.
* tests/test-dprintf-gnu.c: Include it.
(test_function): Remove function.
* modules/dprintf-gnu-tests (Files): Add it.
* tests/test-dzprintf-gnu.c: New file, based on
tests/test-dprintf-gnu.c.
* tests/test-dzprintf-gnu.sh: New file, based on
tests/test-dprintf-gnu.sh.
* modules/dzprintf-gnu-tests: New file.
dzprintf-gnu: New module.
* modules/dzprintf-gnu: New file.
2024-06-30 Bruno Haible <[email protected]>
vdzprintf-gnu: Add tests.
* tests/test-fprintf-gnu.h (test_function): Use RETTYPE instead of
'int'.
* tests/test-fprintf-gnu.c (RETTYPE): New macro.
* tests/test-vdprintf-gnu.c (RETTYPE): New macro.
* tests/test-vfprintf-gnu.c (RETTYPE): New macro.
* tests/test-vdzprintf-gnu.c: New file, based on
tests/test-vdzprintf-posix.c.
* tests/test-vdzprintf-gnu.sh: New file, based on
tests/test-vdzprintf-posix.sh.
* modules/vdzprintf-gnu-tests: New file.
vdzprintf-gnu: New module.
* modules/vdzprintf-gnu: New file.
2024-06-30 Bruno Haible <[email protected]>
dzprintf-posix: Add tests.
* tests/test-dprintf-posix.h: New file, extracted from
tests/test-dprintf-posix.c.
* tests/test-dprintf-posix.c: Include it. Don't include infinity.h.
(test_function): Remove function.
* modules/dprintf-posix-tests (Files): Add it.
* tests/test-dzprintf-posix.c: New file, based on
tests/test-dprintf-posix.c.
* tests/test-dzprintf-posix.sh: New file, based on
tests/test-dprintf-posix.sh.
* modules/dzprintf-posix-tests: New file.
dzprintf-posix: New module.
* modules/dzprintf-posix: New file.
2024-06-30 Bruno Haible <[email protected]>
vdzprintf-posix: Add tests.
* tests/test-fprintf-posix.h (test_function): Use RETTYPE instead of
'int'.
* tests/test-fprintf-posix.c (RETTYPE): New macro.
* tests/test-vdprintf-posix.c (RETTYPE): New macro.
* tests/test-vfprintf-posix.c (RETTYPE): New macro.
* tests/test-xfprintf-posix.c (RETTYPE): New macro.
* tests/test-vdzprintf-posix.c: New file, based on
tests/test-vdprintf-posix.c.
* tests/test-vdzprintf-posix.sh: New file, based on
tests/test-vdprintf-posix.sh.
* modules/vdzprintf-posix-tests: New file.
vdzprintf-posix: New module.
* modules/vdzprintf-posix: New file.
2024-06-30 Bruno Haible <[email protected]>
dprintf: Use vdzprintf.
* lib/stdio.in.h (dprintf): Add specification.
* lib/dprintf.c: Don't include <stdlib.h>, full-write.h, vasnprintf.h.
Include intprops.h.
(dprintf): Implement based on vdzprintf.
* modules/dprintf (Depends-on): Add vdzprintf, intprops. Remove
vasnprintf, free-posix, full-write.
dzprintf: New module.
* lib/stdio.in.h (dzprintf): New declaration.
* lib/dzprintf.c: New file, based on lib/vdzprintf.c.
* m4/stdio_h.m4 (gl_STDIO_H_REQUIRE_DEFAULTS): Initialize
GNULIB_DZPRINTF.
* modules/stdio (Makefile.am): Substitute GNULIB_DZPRINTF.
* modules/dzprintf: New file.
2024-06-30 Bruno Haible <[email protected]>
vdprintf: Use vdzprintf.
* lib/stdio.in.h (vdprintf): Add specification.
* lib/vdprintf.c: Don't include <stdlib.h>, full-write.h, vasnprintf.h.
Include intprops.h.
(vdprintf): Implement based on vdzprintf.
* modules/vdprintf (Depends-on): Add vdzprintf, intprops. Remove
vasnprintf, free-posix, full-write.
vdzprintf: New module.
* lib/stdio.in.h (vdzprintf): New declaration.
* lib/vdzprintf.c: New file, based on lib/vdprintf.c.
* m4/stdio_h.m4 (gl_STDIO_H_REQUIRE_DEFAULTS): Initialize
GNULIB_VDZPRINTF.
* modules/stdio (Makefile.am): Substitute GNULIB_VDZPRINTF.
* modules/vdzprintf: New file.
>From 95d9b651676b861d47736fcab2f1277bdc89712b Mon Sep 17 00:00:00 2001
From: Bruno Haible <[email protected]>
Date: Sun, 30 Jun 2024 17:09:24 +0200
Subject: [PATCH 01/12] vdzprintf: New module.
* lib/stdio.in.h (vdzprintf): New declaration.
* lib/vdzprintf.c: New file, based on lib/vdprintf.c.
* m4/stdio_h.m4 (gl_STDIO_H_REQUIRE_DEFAULTS): Initialize
GNULIB_VDZPRINTF.
* modules/stdio (Makefile.am): Substitute GNULIB_VDZPRINTF.
* modules/vdzprintf: New file.
---
ChangeLog | 10 +++++++
lib/stdio.in.h | 16 +++++++++++
lib/vdzprintf.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++
m4/stdio_h.m4 | 9 ++++---
modules/stdio | 7 ++---
modules/vdzprintf | 29 ++++++++++++++++++++
6 files changed, 133 insertions(+), 7 deletions(-)
create mode 100644 lib/vdzprintf.c
create mode 100644 modules/vdzprintf
diff --git a/ChangeLog b/ChangeLog
index cf44fca935..c75cbe10f1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2024-06-30 Bruno Haible <[email protected]>
+
+ vdzprintf: New module.
+ * lib/stdio.in.h (vdzprintf): New declaration.
+ * lib/vdzprintf.c: New file, based on lib/vdprintf.c.
+ * m4/stdio_h.m4 (gl_STDIO_H_REQUIRE_DEFAULTS): Initialize
+ GNULIB_VDZPRINTF.
+ * modules/stdio (Makefile.am): Substitute GNULIB_VDZPRINTF.
+ * modules/vdzprintf: New file.
+
2024-06-30 Bruno Haible <[email protected]>
*printf-tests: Correct test file descriptions.
diff --git a/lib/stdio.in.h b/lib/stdio.in.h
index bcae688b78..52dc8f30ba 100644
--- a/lib/stdio.in.h
+++ b/lib/stdio.in.h
@@ -1703,6 +1703,22 @@ _GL_CXXALIAS_SYS (vasprintf, int,
_GL_CXXALIASWARN (vasprintf);
#endif
+#if @GNULIB_VDZPRINTF@
+/* Prints formatted output to file descriptor FD.
+ Returns the number of bytes written to the file descriptor. Upon
+ failure, returns -1 with errno set.
+ Failure code EOVERFLOW can only occur when a width > INT_MAX is used.
+ Therefore, if the format string is valid and does not use %ls/%lc
+ directives nor widths, the only possible failure codes are ENOMEM
+ and the possible failure codes from write(), excluding EINTR. */
+_GL_FUNCDECL_SYS (vdzprintf, off64_t,
+ (int fd, const char *restrict format, va_list args)
+ _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (2, 0)
+ _GL_ARG_NONNULL ((2)));
+_GL_CXXALIAS_SYS (vdzprintf, off64_t,
+ (int fd, const char *restrict format, va_list args));
+#endif
+
#if @GNULIB_VDPRINTF@
# if @REPLACE_VDPRINTF@
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
diff --git a/lib/vdzprintf.c b/lib/vdzprintf.c
new file mode 100644
index 0000000000..64c3ab1331
--- /dev/null
+++ b/lib/vdzprintf.c
@@ -0,0 +1,69 @@
+/* Formatted output to a file descriptor.
+ Copyright (C) 2009-2024 Free Software Foundation, Inc.
+
+ This file is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as
+ published by the Free Software Foundation, either version 3 of the
+ License, or (at your option) any later version.
+
+ This file 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 Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this program. If not, see <https://www.gnu.org/licenses/>. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+/* Specification. */
+#include <stdio.h>
+
+#include <errno.h>
+#include <stdarg.h>
+#include <stdlib.h>
+
+#include "full-write.h"
+#include "intprops.h"
+#include "vasnprintf.h"
+
+off64_t
+vdzprintf (int fd, const char *format, va_list args)
+{
+ char buf[2000];
+ char *output;
+ size_t len;
+ size_t lenbuf = sizeof (buf);
+
+ output = vasnprintf (buf, &lenbuf, format, args);
+ len = lenbuf;
+
+ if (!output)
+ return -1;
+
+ if (len > TYPE_MAXIMUM (off64_t))
+ {
+ /* We could write the (huge) output, but then could not return len, as it
+ would be negative. Since we want to use the error code ENOMEM, it is
+ better to treat this case as if vasnprintf had already encountered an
+ out-of-memory situation. */
+ if (output != buf)
+ free (output);
+ errno = ENOMEM;
+ return -1;
+ }
+
+ if (full_write (fd, output, len) < len)
+ {
+ if (output != buf)
+ free (output);
+ return -1;
+ }
+
+ if (output != buf)
+ free (output);
+
+ return len;
+}
diff --git a/m4/stdio_h.m4 b/m4/stdio_h.m4
index f3edc43ccd..8073f6fa5b 100644
--- a/m4/stdio_h.m4
+++ b/m4/stdio_h.m4
@@ -1,5 +1,5 @@
# stdio_h.m4
-# serial 69
+# serial 70
dnl Copyright (C) 2007-2024 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
@@ -173,25 +173,26 @@ AC_DEFUN([gl_STDIO_H_REQUIRE_DEFAULTS]
gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_RENAMEAT])
gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_SCANF])
gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_SNPRINTF])
+ gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_SNZPRINTF])
gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_SPRINTF_POSIX])
gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_STDIO_H_NONBLOCKING])
gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_STDIO_H_SIGPIPE])
+ gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_SZPRINTF])
gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_TMPFILE])
gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_VASPRINTF])
gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_VASZPRINTF])
gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_VFSCANF])
gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_VSCANF])
gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_VDPRINTF])
+ gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_VDZPRINTF])
gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_VFPRINTF])
gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_VFPRINTF_POSIX])
gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_VPRINTF])
gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_VPRINTF_POSIX])
gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_VSNPRINTF])
- gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_VSPRINTF_POSIX])
gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_VSNZPRINTF])
+ gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_VSPRINTF_POSIX])
gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_VSZPRINTF])
- gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_SNZPRINTF])
- gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_SZPRINTF])
dnl Support Microsoft deprecated alias function names by default.
gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MDA_FCLOSEALL], [1])
gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MDA_FDOPEN], [1])
diff --git a/modules/stdio b/modules/stdio
index 319309828f..dcc2bfbbf2 100644
--- a/modules/stdio
+++ b/modules/stdio
@@ -108,13 +108,16 @@ stdio.h: stdio.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H)
-e 's/@''GNULIB_RENAMEAT''@/$(GNULIB_RENAMEAT)/g' \
-e 's/@''GNULIB_SCANF''@/$(GNULIB_SCANF)/g' \
-e 's/@''GNULIB_SNPRINTF''@/$(GNULIB_SNPRINTF)/g' \
+ -e 's/@''GNULIB_SNZPRINTF''@/$(GNULIB_SNZPRINTF)/g' \
-e 's/@''GNULIB_SPRINTF_POSIX''@/$(GNULIB_SPRINTF_POSIX)/g' \
-e 's/@''GNULIB_STDIO_H_NONBLOCKING''@/$(GNULIB_STDIO_H_NONBLOCKING)/g' \
-e 's/@''GNULIB_STDIO_H_SIGPIPE''@/$(GNULIB_STDIO_H_SIGPIPE)/g' \
+ -e 's/@''GNULIB_SZPRINTF''@/$(GNULIB_SZPRINTF)/g' \
-e 's/@''GNULIB_TMPFILE''@/$(GNULIB_TMPFILE)/g' \
-e 's/@''GNULIB_VASPRINTF''@/$(GNULIB_VASPRINTF)/g' \
-e 's/@''GNULIB_VASZPRINTF''@/$(GNULIB_VASZPRINTF)/g' \
-e 's/@''GNULIB_VDPRINTF''@/$(GNULIB_VDPRINTF)/g' \
+ -e 's/@''GNULIB_VDZPRINTF''@/$(GNULIB_VDZPRINTF)/g' \
-e 's/@''GNULIB_VFPRINTF''@/$(GNULIB_VFPRINTF)/g' \
-e 's/@''GNULIB_VFPRINTF_POSIX''@/$(GNULIB_VFPRINTF_POSIX)/g' \
-e 's/@''GNULIB_VFSCANF''@/$(GNULIB_VFSCANF)/g' \
@@ -122,11 +125,9 @@ stdio.h: stdio.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H)
-e 's/@''GNULIB_VPRINTF''@/$(GNULIB_VPRINTF)/g' \
-e 's/@''GNULIB_VPRINTF_POSIX''@/$(GNULIB_VPRINTF_POSIX)/g' \
-e 's/@''GNULIB_VSNPRINTF''@/$(GNULIB_VSNPRINTF)/g' \
- -e 's/@''GNULIB_VSPRINTF_POSIX''@/$(GNULIB_VSPRINTF_POSIX)/g' \
-e 's/@''GNULIB_VSNZPRINTF''@/$(GNULIB_VSNZPRINTF)/g' \
+ -e 's/@''GNULIB_VSPRINTF_POSIX''@/$(GNULIB_VSPRINTF_POSIX)/g' \
-e 's/@''GNULIB_VSZPRINTF''@/$(GNULIB_VSZPRINTF)/g' \
- -e 's/@''GNULIB_SNZPRINTF''@/$(GNULIB_SNZPRINTF)/g' \
- -e 's/@''GNULIB_SZPRINTF''@/$(GNULIB_SZPRINTF)/g' \
-e 's/@''GNULIB_MDA_FCLOSEALL''@/$(GNULIB_MDA_FCLOSEALL)/g' \
-e 's/@''GNULIB_MDA_FDOPEN''@/$(GNULIB_MDA_FDOPEN)/g' \
-e 's/@''GNULIB_MDA_FILENO''@/$(GNULIB_MDA_FILENO)/g' \
diff --git a/modules/vdzprintf b/modules/vdzprintf
new file mode 100644
index 0000000000..496763c82b
--- /dev/null
+++ b/modules/vdzprintf
@@ -0,0 +1,29 @@
+Description:
+vdzprintf() function: print formatted output (without INT_MAX limitation)
+to a file descriptor
+
+Files:
+lib/vdzprintf.c
+
+Depends-on:
+stdio
+vasnprintf
+intprops
+free-posix
+full-write
+errno
+
+configure.ac:
+gl_STDIO_MODULE_INDICATOR([vdzprintf])
+
+Makefile.am:
+lib_SOURCES += vdzprintf.c
+
+Include:
+<stdio.h>
+
+License:
+LGPL
+
+Maintainer:
+all
--
2.34.1
>From 3a40fb5e8dae23beaf54bb104c3e6d916881e0a0 Mon Sep 17 00:00:00 2001
From: Bruno Haible <[email protected]>
Date: Sun, 30 Jun 2024 17:15:28 +0200
Subject: [PATCH 02/12] vdprintf: Use vdzprintf.
* lib/stdio.in.h (vdprintf): Add specification.
* lib/vdprintf.c: Don't include <stdlib.h>, full-write.h, vasnprintf.h.
Include intprops.h.
(vdprintf): Implement based on vdzprintf.
* modules/vdprintf (Depends-on): Add vdzprintf, intprops. Remove
vasnprintf, free-posix, full-write.
---
ChangeLog | 8 ++++++++
lib/stdio.in.h | 3 +++
lib/vdprintf.c | 29 ++++-------------------------
modules/vdprintf | 5 ++---
4 files changed, 17 insertions(+), 28 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index c75cbe10f1..72ecdad3d5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
2024-06-30 Bruno Haible <[email protected]>
+ vdprintf: Use vdzprintf.
+ * lib/stdio.in.h (vdprintf): Add specification.
+ * lib/vdprintf.c: Don't include <stdlib.h>, full-write.h, vasnprintf.h.
+ Include intprops.h.
+ (vdprintf): Implement based on vdzprintf.
+ * modules/vdprintf (Depends-on): Add vdzprintf, intprops. Remove
+ vasnprintf, free-posix, full-write.
+
vdzprintf: New module.
* lib/stdio.in.h (vdzprintf): New declaration.
* lib/vdzprintf.c: New file, based on lib/vdprintf.c.
diff --git a/lib/stdio.in.h b/lib/stdio.in.h
index 52dc8f30ba..03e4cf9ca6 100644
--- a/lib/stdio.in.h
+++ b/lib/stdio.in.h
@@ -1720,6 +1720,9 @@ _GL_CXXALIAS_SYS (vdzprintf, off64_t,
#endif
#if @GNULIB_VDPRINTF@
+/* Prints formatted output to file descriptor FD.
+ Returns the number of bytes written to the file descriptor. Upon
+ failure, returns a negative value. */
# if @REPLACE_VDPRINTF@
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
# define vdprintf rpl_vdprintf
diff --git a/lib/vdprintf.c b/lib/vdprintf.c
index 571e74f90a..263baf9aa2 100644
--- a/lib/vdprintf.c
+++ b/lib/vdprintf.c
@@ -24,40 +24,19 @@
#include <errno.h>
#include <limits.h>
#include <stdarg.h>
-#include <stdlib.h>
-#include "full-write.h"
-#include "vasnprintf.h"
+#include "intprops.h"
int
vdprintf (int fd, const char *format, va_list args)
{
- char buf[2000];
- char *output;
- size_t len;
- size_t lenbuf = sizeof (buf);
+ off64_t ret = vdzprintf (fd, format, args);
- output = vasnprintf (buf, &lenbuf, format, args);
- len = lenbuf;
-
- if (!output)
- return -1;
-
- if (full_write (fd, output, len) < len)
- {
- if (output != buf)
- free (output);
- return -1;
- }
-
- if (output != buf)
- free (output);
-
- if (len > INT_MAX)
+ if (TYPE_MAXIMUM (off64_t) > INT_MAX && ret > INT_MAX)
{
errno = EOVERFLOW;
return -1;
}
- return len;
+ return ret;
}
diff --git a/modules/vdprintf b/modules/vdprintf
index 87192a3fdc..b09dbd748e 100644
--- a/modules/vdprintf
+++ b/modules/vdprintf
@@ -7,9 +7,8 @@ m4/vdprintf.m4
Depends-on:
stdio
-vasnprintf [test $ac_cv_func_vdprintf = no || test $REPLACE_VDPRINTF = 1]
-free-posix [test $ac_cv_func_vdprintf = no || test $REPLACE_VDPRINTF = 1]
-full-write [test $ac_cv_func_vdprintf = no || test $REPLACE_VDPRINTF = 1]
+vdzprintf [test $ac_cv_func_vdprintf = no || test $REPLACE_VDPRINTF = 1]
+intprops [test $ac_cv_func_vdprintf = no || test $REPLACE_VDPRINTF = 1]
errno [test $ac_cv_func_vdprintf = no || test $REPLACE_VDPRINTF = 1]
configure.ac:
--
2.34.1
>From 248ce289f789eda18142f1e6003491bb11061e60 Mon Sep 17 00:00:00 2001
From: Bruno Haible <[email protected]>
Date: Sun, 30 Jun 2024 17:17:14 +0200
Subject: [PATCH 03/12] dzprintf: New module.
* lib/stdio.in.h (dzprintf): New declaration.
* lib/dzprintf.c: New file, based on lib/vdzprintf.c.
* m4/stdio_h.m4 (gl_STDIO_H_REQUIRE_DEFAULTS): Initialize
GNULIB_DZPRINTF.
* modules/stdio (Makefile.am): Substitute GNULIB_DZPRINTF.
* modules/dzprintf: New file.
---
ChangeLog | 10 +++++++
lib/dzprintf.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++++
lib/stdio.in.h | 16 +++++++++++
m4/stdio_h.m4 | 3 +-
modules/dzprintf | 29 +++++++++++++++++++
modules/stdio | 1 +
6 files changed, 130 insertions(+), 1 deletion(-)
create mode 100644 lib/dzprintf.c
create mode 100644 modules/dzprintf
diff --git a/ChangeLog b/ChangeLog
index 72ecdad3d5..9b8a205204 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2024-06-30 Bruno Haible <[email protected]>
+
+ dzprintf: New module.
+ * lib/stdio.in.h (dzprintf): New declaration.
+ * lib/dzprintf.c: New file, based on lib/vdzprintf.c.
+ * m4/stdio_h.m4 (gl_STDIO_H_REQUIRE_DEFAULTS): Initialize
+ GNULIB_DZPRINTF.
+ * modules/stdio (Makefile.am): Substitute GNULIB_DZPRINTF.
+ * modules/dzprintf: New file.
+
2024-06-30 Bruno Haible <[email protected]>
vdprintf: Use vdzprintf.
diff --git a/lib/dzprintf.c b/lib/dzprintf.c
new file mode 100644
index 0000000000..ee8b276a53
--- /dev/null
+++ b/lib/dzprintf.c
@@ -0,0 +1,72 @@
+/* Formatted output to a file descriptor.
+ Copyright (C) 2009-2024 Free Software Foundation, Inc.
+
+ This file is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as
+ published by the Free Software Foundation, either version 3 of the
+ License, or (at your option) any later version.
+
+ This file 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 Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this program. If not, see <https://www.gnu.org/licenses/>. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+/* Specification. */
+#include <stdio.h>
+
+#include <errno.h>
+#include <stdarg.h>
+#include <stdlib.h>
+
+#include "full-write.h"
+#include "intprops.h"
+#include "vasnprintf.h"
+
+off64_t
+dzprintf (int fd, const char *format, ...)
+{
+ va_list args;
+ char buf[2000];
+ char *output;
+ size_t len;
+ size_t lenbuf = sizeof (buf);
+
+ va_start (args, format);
+ output = vasnprintf (buf, &lenbuf, format, args);
+ len = lenbuf;
+ va_end (args);
+
+ if (!output)
+ return -1;
+
+ if (len > TYPE_MAXIMUM (off64_t))
+ {
+ /* We could write the (huge) output, but then could not return len, as it
+ would be negative. Since we want to use the error code ENOMEM, it is
+ better to treat this case as if vasnprintf had already encountered an
+ out-of-memory situation. */
+ if (output != buf)
+ free (output);
+ errno = ENOMEM;
+ return -1;
+ }
+
+ if (full_write (fd, output, len) < len)
+ {
+ if (output != buf)
+ free (output);
+ return -1;
+ }
+
+ if (output != buf)
+ free (output);
+
+ return len;
+}
diff --git a/lib/stdio.in.h b/lib/stdio.in.h
index 03e4cf9ca6..5fac912db2 100644
--- a/lib/stdio.in.h
+++ b/lib/stdio.in.h
@@ -280,6 +280,22 @@
#endif
+#if @GNULIB_DZPRINTF@
+/* Prints formatted output to file descriptor FD.
+ Returns the number of bytes written to the file descriptor. Upon
+ failure, returns -1 with errno set.
+ Failure code EOVERFLOW can only occur when a width > INT_MAX is used.
+ Therefore, if the format string is valid and does not use %ls/%lc
+ directives nor widths, the only possible failure codes are ENOMEM
+ and the possible failure codes from write(), excluding EINTR. */
+_GL_FUNCDECL_SYS (dzprintf, off64_t,
+ (int fd, const char *restrict format, ...)
+ _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (2, 3)
+ _GL_ARG_NONNULL ((2)));
+_GL_CXXALIAS_SYS (dzprintf, off64_t,
+ (int fd, const char *restrict format, ...));
+#endif
+
#if @GNULIB_DPRINTF@
# if @REPLACE_DPRINTF@
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
diff --git a/m4/stdio_h.m4 b/m4/stdio_h.m4
index 8073f6fa5b..126e395fae 100644
--- a/m4/stdio_h.m4
+++ b/m4/stdio_h.m4
@@ -1,5 +1,5 @@
# stdio_h.m4
-# serial 70
+# serial 71
dnl Copyright (C) 2007-2024 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
@@ -133,6 +133,7 @@ AC_DEFUN([gl_STDIO_H_REQUIRE_DEFAULTS]
[
m4_defun(GL_MODULE_INDICATOR_PREFIX[_STDIO_H_MODULE_INDICATOR_DEFAULTS], [
gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_DPRINTF])
+ gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_DZPRINTF])
gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FCLOSE])
gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FDOPEN])
gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_FFLUSH])
diff --git a/modules/dzprintf b/modules/dzprintf
new file mode 100644
index 0000000000..ea3dc9d033
--- /dev/null
+++ b/modules/dzprintf
@@ -0,0 +1,29 @@
+Description:
+dzprintf() function: print formatted output (without INT_MAX limitation)
+to a file descriptor
+
+Files:
+lib/dzprintf.c
+
+Depends-on:
+stdio
+vasnprintf
+intprops
+free-posix
+full-write
+errno
+
+configure.ac:
+gl_STDIO_MODULE_INDICATOR([dzprintf])
+
+Makefile.am:
+lib_SOURCES += dzprintf.c
+
+Include:
+<stdio.h>
+
+License:
+LGPL
+
+Maintainer:
+all
diff --git a/modules/stdio b/modules/stdio
index dcc2bfbbf2..22008a2b90 100644
--- a/modules/stdio
+++ b/modules/stdio
@@ -68,6 +68,7 @@ stdio.h: stdio.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H)
-e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
-e 's|@''NEXT_STDIO_H''@|$(NEXT_STDIO_H)|g' \
-e 's/@''GNULIB_DPRINTF''@/$(GNULIB_DPRINTF)/g' \
+ -e 's/@''GNULIB_DZPRINTF''@/$(GNULIB_DZPRINTF)/g' \
-e 's/@''GNULIB_FCLOSE''@/$(GNULIB_FCLOSE)/g' \
-e 's/@''GNULIB_FDOPEN''@/$(GNULIB_FDOPEN)/g' \
-e 's/@''GNULIB_FFLUSH''@/$(GNULIB_FFLUSH)/g' \
--
2.34.1
>From f320c3a588a5509993cc57bf9a29afdfd6c064e0 Mon Sep 17 00:00:00 2001
From: Bruno Haible <[email protected]>
Date: Sun, 30 Jun 2024 17:18:35 +0200
Subject: [PATCH 04/12] dprintf: Use vdzprintf.
* lib/stdio.in.h (dprintf): Add specification.
* lib/dprintf.c: Don't include <stdlib.h>, full-write.h, vasnprintf.h.
Include intprops.h.
(dprintf): Implement based on vdzprintf.
* modules/dprintf (Depends-on): Add vdzprintf, intprops. Remove
vasnprintf, free-posix, full-write.
---
ChangeLog | 8 ++++++++
lib/dprintf.c | 29 +++++------------------------
lib/stdio.in.h | 3 +++
modules/dprintf | 5 ++---
4 files changed, 18 insertions(+), 27 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 9b8a205204..ddc7cb61c4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
2024-06-30 Bruno Haible <[email protected]>
+ dprintf: Use vdzprintf.
+ * lib/stdio.in.h (dprintf): Add specification.
+ * lib/dprintf.c: Don't include <stdlib.h>, full-write.h, vasnprintf.h.
+ Include intprops.h.
+ (dprintf): Implement based on vdzprintf.
+ * modules/dprintf (Depends-on): Add vdzprintf, intprops. Remove
+ vasnprintf, free-posix, full-write.
+
dzprintf: New module.
* lib/stdio.in.h (dzprintf): New declaration.
* lib/dzprintf.c: New file, based on lib/vdzprintf.c.
diff --git a/lib/dprintf.c b/lib/dprintf.c
index 70d359c345..a543d5c036 100644
--- a/lib/dprintf.c
+++ b/lib/dprintf.c
@@ -24,43 +24,24 @@
#include <errno.h>
#include <limits.h>
#include <stdarg.h>
-#include <stdlib.h>
-#include "full-write.h"
-#include "vasnprintf.h"
+#include "intprops.h"
int
dprintf (int fd, const char *format, ...)
{
- char buf[2000];
- char *output;
- size_t len;
- size_t lenbuf = sizeof (buf);
va_list args;
+ off64_t ret;
va_start (args, format);
- output = vasnprintf (buf, &lenbuf, format, args);
- len = lenbuf;
+ ret = vdzprintf (fd, format, args);
va_end (args);
- if (!output)
- return -1;
-
- if (full_write (fd, output, len) < len)
- {
- if (output != buf)
- free (output);
- return -1;
- }
-
- if (output != buf)
- free (output);
-
- if (len > INT_MAX)
+ if (TYPE_MAXIMUM (off64_t) > INT_MAX && ret > INT_MAX)
{
errno = EOVERFLOW;
return -1;
}
- return len;
+ return ret;
}
diff --git a/lib/stdio.in.h b/lib/stdio.in.h
index 5fac912db2..acbe14cc41 100644
--- a/lib/stdio.in.h
+++ b/lib/stdio.in.h
@@ -297,6 +297,9 @@ _GL_CXXALIAS_SYS (dzprintf, off64_t,
#endif
#if @GNULIB_DPRINTF@
+/* Prints formatted output to file descriptor FD.
+ Returns the number of bytes written to the file descriptor. Upon
+ failure, returns a negative value. */
# if @REPLACE_DPRINTF@
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
# define dprintf rpl_dprintf
diff --git a/modules/dprintf b/modules/dprintf
index 653cb9380c..1e9d208df9 100644
--- a/modules/dprintf
+++ b/modules/dprintf
@@ -7,9 +7,8 @@ m4/dprintf.m4
Depends-on:
stdio
-vasnprintf [test $ac_cv_func_dprintf = no || test $REPLACE_DPRINTF = 1]
-free-posix [test $ac_cv_func_dprintf = no || test $REPLACE_DPRINTF = 1]
-full-write [test $ac_cv_func_dprintf = no || test $REPLACE_DPRINTF = 1]
+vdzprintf [test $ac_cv_func_dprintf = no || test $REPLACE_DPRINTF = 1]
+intprops [test $ac_cv_func_dprintf = no || test $REPLACE_DPRINTF = 1]
errno [test $ac_cv_func_dprintf = no || test $REPLACE_DPRINTF = 1]
configure.ac:
--
2.34.1
>From 88c874ae861bb878b02c52eb268efadda5a6dfa5 Mon Sep 17 00:00:00 2001
From: Bruno Haible <[email protected]>
Date: Sun, 30 Jun 2024 17:20:02 +0200
Subject: [PATCH 05/12] vdzprintf-posix: New module.
* modules/vdzprintf-posix: New file.
---
ChangeLog | 5 +++++
modules/vdzprintf-posix | 22 ++++++++++++++++++++++
2 files changed, 27 insertions(+)
create mode 100644 modules/vdzprintf-posix
diff --git a/ChangeLog b/ChangeLog
index ddc7cb61c4..a13e83c694 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2024-06-30 Bruno Haible <[email protected]>
+
+ vdzprintf-posix: New module.
+ * modules/vdzprintf-posix: New file.
+
2024-06-30 Bruno Haible <[email protected]>
dprintf: Use vdzprintf.
diff --git a/modules/vdzprintf-posix b/modules/vdzprintf-posix
new file mode 100644
index 0000000000..4aa6bba1af
--- /dev/null
+++ b/modules/vdzprintf-posix
@@ -0,0 +1,22 @@
+Description:
+vdzprintf() function with POSIX compatible format string interpretation
+
+Files:
+
+Depends-on:
+vdzprintf
+mixin/printf-posix
+
+configure.ac:
+gl_PREREQ_VASNPRINTF_WITH_POSIX_EXTRAS
+
+Makefile.am:
+
+Include:
+<stdio.h>
+
+License:
+LGPL
+
+Maintainer:
+all
--
2.34.1
>From 5aecec4e4370e72304ca13a0f690306835474204 Mon Sep 17 00:00:00 2001
From: Bruno Haible <[email protected]>
Date: Sun, 30 Jun 2024 17:21:04 +0200
Subject: [PATCH 06/12] vdzprintf-posix: Add tests.
* tests/test-fprintf-posix.h (test_function): Use RETTYPE instead of
'int'.
* tests/test-fprintf-posix.c (RETTYPE): New macro.
* tests/test-vdprintf-posix.c (RETTYPE): New macro.
* tests/test-vfprintf-posix.c (RETTYPE): New macro.
* tests/test-xfprintf-posix.c (RETTYPE): New macro.
* tests/test-vdzprintf-posix.c: New file, based on
tests/test-vdprintf-posix.c.
* tests/test-vdzprintf-posix.sh: New file, based on
tests/test-vdprintf-posix.sh.
* modules/vdzprintf-posix-tests: New file.
---
ChangeLog | 13 +++++++++
modules/vdzprintf-posix-tests | 16 +++++++++++
tests/test-fprintf-posix.c | 1 +
tests/test-fprintf-posix.h | 4 +--
tests/test-vdprintf-posix.c | 1 +
tests/test-vdzprintf-posix.c | 50 +++++++++++++++++++++++++++++++++++
tests/test-vdzprintf-posix.sh | 16 +++++++++++
tests/test-vfprintf-posix.c | 1 +
tests/test-xfprintf-posix.c | 1 +
9 files changed, 101 insertions(+), 2 deletions(-)
create mode 100644 modules/vdzprintf-posix-tests
create mode 100644 tests/test-vdzprintf-posix.c
create mode 100755 tests/test-vdzprintf-posix.sh
diff --git a/ChangeLog b/ChangeLog
index a13e83c694..4b2988dea5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,18 @@
2024-06-30 Bruno Haible <[email protected]>
+ vdzprintf-posix: Add tests.
+ * tests/test-fprintf-posix.h (test_function): Use RETTYPE instead of
+ 'int'.
+ * tests/test-fprintf-posix.c (RETTYPE): New macro.
+ * tests/test-vdprintf-posix.c (RETTYPE): New macro.
+ * tests/test-vfprintf-posix.c (RETTYPE): New macro.
+ * tests/test-xfprintf-posix.c (RETTYPE): New macro.
+ * tests/test-vdzprintf-posix.c: New file, based on
+ tests/test-vdprintf-posix.c.
+ * tests/test-vdzprintf-posix.sh: New file, based on
+ tests/test-vdprintf-posix.sh.
+ * modules/vdzprintf-posix-tests: New file.
+
vdzprintf-posix: New module.
* modules/vdzprintf-posix: New file.
diff --git a/modules/vdzprintf-posix-tests b/modules/vdzprintf-posix-tests
new file mode 100644
index 0000000000..8cbf0d61b4
--- /dev/null
+++ b/modules/vdzprintf-posix-tests
@@ -0,0 +1,16 @@
+Files:
+tests/test-vdzprintf-posix.sh
+tests/test-vdzprintf-posix.c
+tests/test-fprintf-posix.h
+tests/test-printf-posix.output
+tests/infinity.h
+tests/macros.h
+
+Depends-on:
+stdint
+
+configure.ac:
+
+Makefile.am:
+TESTS += test-vdzprintf-posix.sh
+check_PROGRAMS += test-vdzprintf-posix
diff --git a/tests/test-fprintf-posix.c b/tests/test-fprintf-posix.c
index f929faeca7..019cdcf2bc 100644
--- a/tests/test-fprintf-posix.c
+++ b/tests/test-fprintf-posix.c
@@ -30,6 +30,7 @@ SIGNATURE_CHECK (fprintf, int, (FILE *, char const *, ...));
#include "macros.h"
+#define RETTYPE int
#include "test-fprintf-posix.h"
int
diff --git a/tests/test-fprintf-posix.h b/tests/test-fprintf-posix.h
index 8576f58324..eac279ddb8 100644
--- a/tests/test-fprintf-posix.h
+++ b/tests/test-fprintf-posix.h
@@ -1,4 +1,4 @@
-/* Test of POSIX compatible [v]fprintf() and vdprintf() functions.
+/* Test of POSIX compatible [v]fprintf() and vd[z]printf() functions.
Copyright (C) 2007-2024 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
@@ -19,7 +19,7 @@
#include "infinity.h"
static void
-test_function (int (*my_fprintf) (FILE *, const char *, ...))
+test_function (RETTYPE (*my_fprintf) (FILE *, const char *, ...))
{
/* Here we don't test output that may be platform dependent.
The bulk of the tests is done as part of the 'vasnprintf-posix' module. */
diff --git a/tests/test-vdprintf-posix.c b/tests/test-vdprintf-posix.c
index 0d6b6e39b3..eec47b0bc6 100644
--- a/tests/test-vdprintf-posix.c
+++ b/tests/test-vdprintf-posix.c
@@ -30,6 +30,7 @@ SIGNATURE_CHECK (vdprintf, int, (int, char const *, va_list));
#include "macros.h"
+#define RETTYPE int
#include "test-fprintf-posix.h"
static int
diff --git a/tests/test-vdzprintf-posix.c b/tests/test-vdzprintf-posix.c
new file mode 100644
index 0000000000..f9573fc18d
--- /dev/null
+++ b/tests/test-vdzprintf-posix.c
@@ -0,0 +1,50 @@
+/* Test of POSIX compatible vdzprintf() function.
+ Copyright (C) 2007-2024 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 <[email protected]>, 2009. */
+
+#include <config.h>
+
+#include <stdio.h>
+
+#include <stdarg.h>
+#include <stddef.h>
+#include <stdint.h>
+#include <string.h>
+
+#include "macros.h"
+
+#define RETTYPE off64_t
+#include "test-fprintf-posix.h"
+
+static off64_t
+my_fzprintf (FILE *fp, const char *format, ...)
+{
+ va_list args;
+ off64_t ret;
+
+ va_start (args, format);
+ ret = vdzprintf (fileno (fp), format, args);
+ va_end (args);
+ return ret;
+}
+
+int
+main (int argc, char *argv[])
+{
+ test_function (my_fzprintf);
+ return test_exit_status;
+}
diff --git a/tests/test-vdzprintf-posix.sh b/tests/test-vdzprintf-posix.sh
new file mode 100755
index 0000000000..be2f5d79b9
--- /dev/null
+++ b/tests/test-vdzprintf-posix.sh
@@ -0,0 +1,16 @@
+#!/bin/sh
+
+tmpfiles=""
+trap 'rm -fr $tmpfiles' HUP INT QUIT TERM
+
+tmpfiles="$tmpfiles t-vdzprintf-posix.tmp t-vdzprintf-posix.out"
+${CHECKER} ./test-vdzprintf-posix${EXEEXT} > t-vdzprintf-posix.tmp || exit 1
+LC_ALL=C tr -d '\r' < t-vdzprintf-posix.tmp > t-vdzprintf-posix.out || exit 1
+
+: "${DIFF=diff}"
+${DIFF} "${srcdir}/test-printf-posix.output" t-vdzprintf-posix.out
+result=$?
+
+rm -fr $tmpfiles
+
+exit $result
diff --git a/tests/test-vfprintf-posix.c b/tests/test-vfprintf-posix.c
index ae9c8f35bc..c64c1d2c4d 100644
--- a/tests/test-vfprintf-posix.c
+++ b/tests/test-vfprintf-posix.c
@@ -30,6 +30,7 @@ SIGNATURE_CHECK (vfprintf, int, (FILE *, char const *, va_list));
#include "macros.h"
+#define RETTYPE int
#include "test-fprintf-posix.h"
static int
diff --git a/tests/test-xfprintf-posix.c b/tests/test-xfprintf-posix.c
index e17f5cbac3..372a8fd830 100644
--- a/tests/test-xfprintf-posix.c
+++ b/tests/test-xfprintf-posix.c
@@ -27,6 +27,7 @@
#include "macros.h"
+#define RETTYPE int
#include "test-fprintf-posix.h"
int
--
2.34.1
>From e92992370d2e75ca26c25003b31f963350d5d090 Mon Sep 17 00:00:00 2001
From: Bruno Haible <[email protected]>
Date: Sun, 30 Jun 2024 17:25:05 +0200
Subject: [PATCH 07/12] dzprintf-posix: New module.
* modules/dzprintf-posix: New file.
---
ChangeLog | 5 +++++
modules/dzprintf-posix | 22 ++++++++++++++++++++++
2 files changed, 27 insertions(+)
create mode 100644 modules/dzprintf-posix
diff --git a/ChangeLog b/ChangeLog
index 4b2988dea5..4a915494fd 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2024-06-30 Bruno Haible <[email protected]>
+
+ dzprintf-posix: New module.
+ * modules/dzprintf-posix: New file.
+
2024-06-30 Bruno Haible <[email protected]>
vdzprintf-posix: Add tests.
diff --git a/modules/dzprintf-posix b/modules/dzprintf-posix
new file mode 100644
index 0000000000..edff5ccd52
--- /dev/null
+++ b/modules/dzprintf-posix
@@ -0,0 +1,22 @@
+Description:
+dzprintf() function with POSIX compatible format string interpretation
+
+Files:
+
+Depends-on:
+dzprintf
+mixin/printf-posix
+
+configure.ac:
+gl_PREREQ_VASNPRINTF_WITH_POSIX_EXTRAS
+
+Makefile.am:
+
+Include:
+<stdio.h>
+
+License:
+LGPL
+
+Maintainer:
+all
--
2.34.1
>From 05f70dbdcfeea8f012f10570f8ffa09dde377dbb Mon Sep 17 00:00:00 2001
From: Bruno Haible <[email protected]>
Date: Sun, 30 Jun 2024 17:25:46 +0200
Subject: [PATCH 08/12] dzprintf-posix: Add tests.
* tests/test-dprintf-posix.h: New file, extracted from
tests/test-dprintf-posix.c.
* tests/test-dprintf-posix.c: Include it. Don't include infinity.h.
(test_function): Remove function.
* modules/dprintf-posix-tests (Files): Add it.
* tests/test-dzprintf-posix.c: New file, based on
tests/test-dprintf-posix.c.
* tests/test-dzprintf-posix.sh: New file, based on
tests/test-dprintf-posix.sh.
* modules/dzprintf-posix-tests: New file.
---
ChangeLog | 12 +++
modules/dprintf-posix-tests | 1 +
modules/dzprintf-posix-tests | 16 ++++
tests/test-dprintf-posix.c | 142 +------------------------------
tests/test-dprintf-posix.h | 159 +++++++++++++++++++++++++++++++++++
tests/test-dzprintf-posix.c | 37 ++++++++
tests/test-dzprintf-posix.sh | 16 ++++
7 files changed, 243 insertions(+), 140 deletions(-)
create mode 100644 modules/dzprintf-posix-tests
create mode 100644 tests/test-dprintf-posix.h
create mode 100644 tests/test-dzprintf-posix.c
create mode 100755 tests/test-dzprintf-posix.sh
diff --git a/ChangeLog b/ChangeLog
index 4a915494fd..d4763ea449 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,17 @@
2024-06-30 Bruno Haible <[email protected]>
+ dzprintf-posix: Add tests.
+ * tests/test-dprintf-posix.h: New file, extracted from
+ tests/test-dprintf-posix.c.
+ * tests/test-dprintf-posix.c: Include it. Don't include infinity.h.
+ (test_function): Remove function.
+ * modules/dprintf-posix-tests (Files): Add it.
+ * tests/test-dzprintf-posix.c: New file, based on
+ tests/test-dprintf-posix.c.
+ * tests/test-dzprintf-posix.sh: New file, based on
+ tests/test-dprintf-posix.sh.
+ * modules/dzprintf-posix-tests: New file.
+
dzprintf-posix: New module.
* modules/dzprintf-posix: New file.
diff --git a/modules/dprintf-posix-tests b/modules/dprintf-posix-tests
index 09ebbc06f9..a205742084 100644
--- a/modules/dprintf-posix-tests
+++ b/modules/dprintf-posix-tests
@@ -1,6 +1,7 @@
Files:
tests/test-dprintf-posix.sh
tests/test-dprintf-posix.c
+tests/test-dprintf-posix.h
tests/test-printf-posix.output
tests/test-dprintf-posix2.sh
tests/test-dprintf-posix2.c
diff --git a/modules/dzprintf-posix-tests b/modules/dzprintf-posix-tests
new file mode 100644
index 0000000000..c50df12aee
--- /dev/null
+++ b/modules/dzprintf-posix-tests
@@ -0,0 +1,16 @@
+Files:
+tests/test-dzprintf-posix.sh
+tests/test-dzprintf-posix.c
+tests/test-dprintf-posix.h
+tests/test-printf-posix.output
+tests/infinity.h
+tests/macros.h
+
+Depends-on:
+stdint
+
+configure.ac:
+
+Makefile.am:
+TESTS += test-dzprintf-posix.sh
+check_PROGRAMS += test-dzprintf-posix
diff --git a/tests/test-dprintf-posix.c b/tests/test-dprintf-posix.c
index 4d952baa99..122f3ecdc6 100644
--- a/tests/test-dprintf-posix.c
+++ b/tests/test-dprintf-posix.c
@@ -27,148 +27,10 @@ SIGNATURE_CHECK (dprintf, int, (int, const char *, ...));
#include <stdint.h>
#include <string.h>
-#include "infinity.h"
#include "macros.h"
-static void
-test_function (int (*my_dprintf) (int, const char *, ...))
-{
- /* Here we don't test output that may be platform dependent.
- The bulk of the tests is done as part of the 'vasnprintf-posix' module. */
-
- /* Test support of size specifiers as in C99. */
-
- my_dprintf (fileno (stdout), "%ju %d\n", (uintmax_t) 12345671, 33, 44, 55);
-
- my_dprintf (fileno (stdout), "%zu %d\n", (size_t) 12345672, 33, 44, 55);
-
- my_dprintf (fileno (stdout), "%tu %d\n", (ptrdiff_t) 12345673, 33, 44, 55);
-
- /* Test the support of the 'a' and 'A' conversion specifier for hexadecimal
- output of floating-point numbers. */
-
- /* Positive zero. */
- my_dprintf (fileno (stdout), "%a %d\n", 0.0, 33, 44, 55);
-
- /* Positive infinity. */
- my_dprintf (fileno (stdout), "%a %d\n", Infinityd (), 33, 44, 55);
-
- /* Negative infinity. */
- my_dprintf (fileno (stdout), "%a %d\n", - Infinityd (), 33, 44, 55);
-
- /* FLAG_ZERO with infinite number. */
- my_dprintf (fileno (stdout), "%010a %d\n", Infinityd (), 33, 44, 55);
-
- /* Test the support of the %f format directive. */
-
- /* A positive number. */
- my_dprintf (fileno (stdout), "%f %d\n", 12.75, 33, 44, 55);
-
- /* A larger positive number. */
- my_dprintf (fileno (stdout), "%f %d\n", 1234567.0, 33, 44, 55);
-
- /* A negative number. */
- my_dprintf (fileno (stdout), "%f %d\n", -0.03125, 33, 44, 55);
-
- /* Positive zero. */
- my_dprintf (fileno (stdout), "%f %d\n", 0.0, 33, 44, 55);
-
- /* FLAG_ZERO. */
- my_dprintf (fileno (stdout), "%015f %d\n", 1234.0, 33, 44, 55);
-
- /* Precision. */
- my_dprintf (fileno (stdout), "%.f %d\n", 1234.0, 33, 44, 55);
-
- /* Precision with no rounding. */
- my_dprintf (fileno (stdout), "%.2f %d\n", 999.95, 33, 44, 55);
-
- /* Precision with rounding. */
- my_dprintf (fileno (stdout), "%.2f %d\n", 999.996, 33, 44, 55);
-
- /* A positive number. */
- my_dprintf (fileno (stdout), "%Lf %d\n", 12.75L, 33, 44, 55);
-
- /* A larger positive number. */
- my_dprintf (fileno (stdout), "%Lf %d\n", 1234567.0L, 33, 44, 55);
-
- /* A negative number. */
- my_dprintf (fileno (stdout), "%Lf %d\n", -0.03125L, 33, 44, 55);
-
- /* Positive zero. */
- my_dprintf (fileno (stdout), "%Lf %d\n", 0.0L, 33, 44, 55);
-
- /* FLAG_ZERO. */
- my_dprintf (fileno (stdout), "%015Lf %d\n", 1234.0L, 33, 44, 55);
-
- /* Precision. */
- my_dprintf (fileno (stdout), "%.Lf %d\n", 1234.0L, 33, 44, 55);
-
- /* Precision with no rounding. */
- my_dprintf (fileno (stdout), "%.2Lf %d\n", 999.95L, 33, 44, 55);
-
- /* Precision with rounding. */
- my_dprintf (fileno (stdout), "%.2Lf %d\n", 999.996L, 33, 44, 55);
-
- /* Test the support of the %F format directive. */
-
- /* A positive number. */
- my_dprintf (fileno (stdout), "%F %d\n", 12.75, 33, 44, 55);
-
- /* A larger positive number. */
- my_dprintf (fileno (stdout), "%F %d\n", 1234567.0, 33, 44, 55);
-
- /* A negative number. */
- my_dprintf (fileno (stdout), "%F %d\n", -0.03125, 33, 44, 55);
-
- /* Positive zero. */
- my_dprintf (fileno (stdout), "%F %d\n", 0.0, 33, 44, 55);
-
- /* FLAG_ZERO. */
- my_dprintf (fileno (stdout), "%015F %d\n", 1234.0, 33, 44, 55);
-
- /* Precision. */
- my_dprintf (fileno (stdout), "%.F %d\n", 1234.0, 33, 44, 55);
-
- /* Precision with no rounding. */
- my_dprintf (fileno (stdout), "%.2F %d\n", 999.95, 33, 44, 55);
-
- /* Precision with rounding. */
- my_dprintf (fileno (stdout), "%.2F %d\n", 999.996, 33, 44, 55);
-
- /* A positive number. */
- my_dprintf (fileno (stdout), "%LF %d\n", 12.75L, 33, 44, 55);
-
- /* A larger positive number. */
- my_dprintf (fileno (stdout), "%LF %d\n", 1234567.0L, 33, 44, 55);
-
- /* A negative number. */
- my_dprintf (fileno (stdout), "%LF %d\n", -0.03125L, 33, 44, 55);
-
- /* Positive zero. */
- my_dprintf (fileno (stdout), "%LF %d\n", 0.0L, 33, 44, 55);
-
- /* FLAG_ZERO. */
- my_dprintf (fileno (stdout), "%015LF %d\n", 1234.0L, 33, 44, 55);
-
- /* Precision. */
- my_dprintf (fileno (stdout), "%.LF %d\n", 1234.0L, 33, 44, 55);
-
- /* Precision with no rounding. */
- my_dprintf (fileno (stdout), "%.2LF %d\n", 999.95L, 33, 44, 55);
-
- /* Precision with rounding. */
- my_dprintf (fileno (stdout), "%.2LF %d\n", 999.996L, 33, 44, 55);
-
- /* Test the support of the %b format directive. */
-
- /* This test would fail on glibc 2.34, musl libc, macOS 14,
- FreeBSD 13.2, NetBSD 10.0, OpenBSD 7.5, AIX 7.3, Solaris 11.4. */
- my_dprintf (fileno (stdout), "%b %d\n", 12345, 33, 44, 55);
-
- /* Test the support of the POSIX/XSI format strings with positions. */
-
- my_dprintf (fileno (stdout), "%2$d %1$d\n", 33, 55);
-}
+#define RETTYPE int
+#include "test-dprintf-posix.h"
int
main (int argc, char *argv[])
diff --git a/tests/test-dprintf-posix.h b/tests/test-dprintf-posix.h
new file mode 100644
index 0000000000..97d763fa5a
--- /dev/null
+++ b/tests/test-dprintf-posix.h
@@ -0,0 +1,159 @@
+/* Test of d[z]printf() with POSIX compatible format string interpretation.
+ Copyright (C) 2007-2024 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 <[email protected]>, 2009. */
+
+#include "infinity.h"
+
+static void
+test_function (RETTYPE (*my_dprintf) (int, const char *, ...))
+{
+ /* Here we don't test output that may be platform dependent.
+ The bulk of the tests is done as part of the 'vasnprintf-posix' module. */
+
+ /* Test support of size specifiers as in C99. */
+
+ my_dprintf (fileno (stdout), "%ju %d\n", (uintmax_t) 12345671, 33, 44, 55);
+
+ my_dprintf (fileno (stdout), "%zu %d\n", (size_t) 12345672, 33, 44, 55);
+
+ my_dprintf (fileno (stdout), "%tu %d\n", (ptrdiff_t) 12345673, 33, 44, 55);
+
+ /* Test the support of the 'a' and 'A' conversion specifier for hexadecimal
+ output of floating-point numbers. */
+
+ /* Positive zero. */
+ my_dprintf (fileno (stdout), "%a %d\n", 0.0, 33, 44, 55);
+
+ /* Positive infinity. */
+ my_dprintf (fileno (stdout), "%a %d\n", Infinityd (), 33, 44, 55);
+
+ /* Negative infinity. */
+ my_dprintf (fileno (stdout), "%a %d\n", - Infinityd (), 33, 44, 55);
+
+ /* FLAG_ZERO with infinite number. */
+ my_dprintf (fileno (stdout), "%010a %d\n", Infinityd (), 33, 44, 55);
+
+ /* Test the support of the %f format directive. */
+
+ /* A positive number. */
+ my_dprintf (fileno (stdout), "%f %d\n", 12.75, 33, 44, 55);
+
+ /* A larger positive number. */
+ my_dprintf (fileno (stdout), "%f %d\n", 1234567.0, 33, 44, 55);
+
+ /* A negative number. */
+ my_dprintf (fileno (stdout), "%f %d\n", -0.03125, 33, 44, 55);
+
+ /* Positive zero. */
+ my_dprintf (fileno (stdout), "%f %d\n", 0.0, 33, 44, 55);
+
+ /* FLAG_ZERO. */
+ my_dprintf (fileno (stdout), "%015f %d\n", 1234.0, 33, 44, 55);
+
+ /* Precision. */
+ my_dprintf (fileno (stdout), "%.f %d\n", 1234.0, 33, 44, 55);
+
+ /* Precision with no rounding. */
+ my_dprintf (fileno (stdout), "%.2f %d\n", 999.95, 33, 44, 55);
+
+ /* Precision with rounding. */
+ my_dprintf (fileno (stdout), "%.2f %d\n", 999.996, 33, 44, 55);
+
+ /* A positive number. */
+ my_dprintf (fileno (stdout), "%Lf %d\n", 12.75L, 33, 44, 55);
+
+ /* A larger positive number. */
+ my_dprintf (fileno (stdout), "%Lf %d\n", 1234567.0L, 33, 44, 55);
+
+ /* A negative number. */
+ my_dprintf (fileno (stdout), "%Lf %d\n", -0.03125L, 33, 44, 55);
+
+ /* Positive zero. */
+ my_dprintf (fileno (stdout), "%Lf %d\n", 0.0L, 33, 44, 55);
+
+ /* FLAG_ZERO. */
+ my_dprintf (fileno (stdout), "%015Lf %d\n", 1234.0L, 33, 44, 55);
+
+ /* Precision. */
+ my_dprintf (fileno (stdout), "%.Lf %d\n", 1234.0L, 33, 44, 55);
+
+ /* Precision with no rounding. */
+ my_dprintf (fileno (stdout), "%.2Lf %d\n", 999.95L, 33, 44, 55);
+
+ /* Precision with rounding. */
+ my_dprintf (fileno (stdout), "%.2Lf %d\n", 999.996L, 33, 44, 55);
+
+ /* Test the support of the %F format directive. */
+
+ /* A positive number. */
+ my_dprintf (fileno (stdout), "%F %d\n", 12.75, 33, 44, 55);
+
+ /* A larger positive number. */
+ my_dprintf (fileno (stdout), "%F %d\n", 1234567.0, 33, 44, 55);
+
+ /* A negative number. */
+ my_dprintf (fileno (stdout), "%F %d\n", -0.03125, 33, 44, 55);
+
+ /* Positive zero. */
+ my_dprintf (fileno (stdout), "%F %d\n", 0.0, 33, 44, 55);
+
+ /* FLAG_ZERO. */
+ my_dprintf (fileno (stdout), "%015F %d\n", 1234.0, 33, 44, 55);
+
+ /* Precision. */
+ my_dprintf (fileno (stdout), "%.F %d\n", 1234.0, 33, 44, 55);
+
+ /* Precision with no rounding. */
+ my_dprintf (fileno (stdout), "%.2F %d\n", 999.95, 33, 44, 55);
+
+ /* Precision with rounding. */
+ my_dprintf (fileno (stdout), "%.2F %d\n", 999.996, 33, 44, 55);
+
+ /* A positive number. */
+ my_dprintf (fileno (stdout), "%LF %d\n", 12.75L, 33, 44, 55);
+
+ /* A larger positive number. */
+ my_dprintf (fileno (stdout), "%LF %d\n", 1234567.0L, 33, 44, 55);
+
+ /* A negative number. */
+ my_dprintf (fileno (stdout), "%LF %d\n", -0.03125L, 33, 44, 55);
+
+ /* Positive zero. */
+ my_dprintf (fileno (stdout), "%LF %d\n", 0.0L, 33, 44, 55);
+
+ /* FLAG_ZERO. */
+ my_dprintf (fileno (stdout), "%015LF %d\n", 1234.0L, 33, 44, 55);
+
+ /* Precision. */
+ my_dprintf (fileno (stdout), "%.LF %d\n", 1234.0L, 33, 44, 55);
+
+ /* Precision with no rounding. */
+ my_dprintf (fileno (stdout), "%.2LF %d\n", 999.95L, 33, 44, 55);
+
+ /* Precision with rounding. */
+ my_dprintf (fileno (stdout), "%.2LF %d\n", 999.996L, 33, 44, 55);
+
+ /* Test the support of the %b format directive. */
+
+ /* This test would fail on glibc 2.34, musl libc, macOS 14,
+ FreeBSD 13.2, NetBSD 10.0, OpenBSD 7.5, AIX 7.3, Solaris 11.4. */
+ my_dprintf (fileno (stdout), "%b %d\n", 12345, 33, 44, 55);
+
+ /* Test the support of the POSIX/XSI format strings with positions. */
+
+ my_dprintf (fileno (stdout), "%2$d %1$d\n", 33, 55);
+}
diff --git a/tests/test-dzprintf-posix.c b/tests/test-dzprintf-posix.c
new file mode 100644
index 0000000000..736645fafe
--- /dev/null
+++ b/tests/test-dzprintf-posix.c
@@ -0,0 +1,37 @@
+/* Test of dzprintf() with POSIX compatible format string interpretation.
+ Copyright (C) 2007-2024 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 <[email protected]>, 2009. */
+
+#include <config.h>
+
+#include <stdio.h>
+
+#include <stddef.h>
+#include <stdint.h>
+#include <string.h>
+
+#include "macros.h"
+
+#define RETTYPE off64_t
+#include "test-dprintf-posix.h"
+
+int
+main (int argc, char *argv[])
+{
+ test_function (dzprintf);
+ return test_exit_status;
+}
diff --git a/tests/test-dzprintf-posix.sh b/tests/test-dzprintf-posix.sh
new file mode 100755
index 0000000000..e4325867c2
--- /dev/null
+++ b/tests/test-dzprintf-posix.sh
@@ -0,0 +1,16 @@
+#!/bin/sh
+
+tmpfiles=""
+trap 'rm -fr $tmpfiles' HUP INT QUIT TERM
+
+tmpfiles="$tmpfiles t-dzprintf-posix.tmp t-dzprintf-posix.out"
+${CHECKER} ./test-dzprintf-posix${EXEEXT} > t-dzprintf-posix.tmp || exit 1
+LC_ALL=C tr -d '\r' < t-dzprintf-posix.tmp > t-dzprintf-posix.out || exit 1
+
+: "${DIFF=diff}"
+${DIFF} "${srcdir}/test-printf-posix.output" t-dzprintf-posix.out
+result=$?
+
+rm -fr $tmpfiles
+
+exit $result
--
2.34.1
>From c2aa6def90e920ec9ddfcea733b079f110f14b39 Mon Sep 17 00:00:00 2001
From: Bruno Haible <[email protected]>
Date: Sun, 30 Jun 2024 17:28:59 +0200
Subject: [PATCH 09/12] vdzprintf-gnu: New module.
* modules/vdzprintf-gnu: New file.
---
ChangeLog | 5 +++++
modules/vdzprintf-gnu | 23 +++++++++++++++++++++++
2 files changed, 28 insertions(+)
create mode 100644 modules/vdzprintf-gnu
diff --git a/ChangeLog b/ChangeLog
index d4763ea449..bae1f68d0e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2024-06-30 Bruno Haible <[email protected]>
+
+ vdzprintf-gnu: New module.
+ * modules/vdzprintf-gnu: New file.
+
2024-06-30 Bruno Haible <[email protected]>
dzprintf-posix: Add tests.
diff --git a/modules/vdzprintf-gnu b/modules/vdzprintf-gnu
new file mode 100644
index 0000000000..f28e51ef02
--- /dev/null
+++ b/modules/vdzprintf-gnu
@@ -0,0 +1,23 @@
+Description:
+vdzprintf() function
+with POSIX and GNU compatible format string interpretation
+
+Files:
+
+Depends-on:
+vdzprintf-posix
+mixin/printf-gnu
+
+configure.ac:
+gl_PREREQ_VASNPRINTF_WITH_GNU_EXTRAS
+
+Makefile.am:
+
+Include:
+<stdio.h>
+
+License:
+LGPL
+
+Maintainer:
+all
--
2.34.1
>From 5db947823d2e3e2a01fabedc786c3b5ea2cf81c1 Mon Sep 17 00:00:00 2001
From: Bruno Haible <[email protected]>
Date: Sun, 30 Jun 2024 17:29:44 +0200
Subject: [PATCH 10/12] vdzprintf-gnu: Add tests.
* tests/test-fprintf-gnu.h (test_function): Use RETTYPE instead of
'int'.
* tests/test-fprintf-gnu.c (RETTYPE): New macro.
* tests/test-vdprintf-gnu.c (RETTYPE): New macro.
* tests/test-vfprintf-gnu.c (RETTYPE): New macro.
* tests/test-vdzprintf-gnu.c: New file, based on
tests/test-vdzprintf-posix.c.
* tests/test-vdzprintf-gnu.sh: New file, based on
tests/test-vdzprintf-posix.sh.
* modules/vdzprintf-gnu-tests: New file.
---
ChangeLog | 12 +++++++++
modules/vdzprintf-gnu-tests | 16 ++++++++++++
tests/test-fprintf-gnu.c | 1 +
tests/test-fprintf-gnu.h | 4 +--
tests/test-vdprintf-gnu.c | 1 +
tests/test-vdzprintf-gnu.c | 50 +++++++++++++++++++++++++++++++++++++
tests/test-vdzprintf-gnu.sh | 16 ++++++++++++
tests/test-vfprintf-gnu.c | 1 +
8 files changed, 99 insertions(+), 2 deletions(-)
create mode 100644 modules/vdzprintf-gnu-tests
create mode 100644 tests/test-vdzprintf-gnu.c
create mode 100755 tests/test-vdzprintf-gnu.sh
diff --git a/ChangeLog b/ChangeLog
index bae1f68d0e..03746bb590 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,17 @@
2024-06-30 Bruno Haible <[email protected]>
+ vdzprintf-gnu: Add tests.
+ * tests/test-fprintf-gnu.h (test_function): Use RETTYPE instead of
+ 'int'.
+ * tests/test-fprintf-gnu.c (RETTYPE): New macro.
+ * tests/test-vdprintf-gnu.c (RETTYPE): New macro.
+ * tests/test-vfprintf-gnu.c (RETTYPE): New macro.
+ * tests/test-vdzprintf-gnu.c: New file, based on
+ tests/test-vdzprintf-posix.c.
+ * tests/test-vdzprintf-gnu.sh: New file, based on
+ tests/test-vdzprintf-posix.sh.
+ * modules/vdzprintf-gnu-tests: New file.
+
vdzprintf-gnu: New module.
* modules/vdzprintf-gnu: New file.
diff --git a/modules/vdzprintf-gnu-tests b/modules/vdzprintf-gnu-tests
new file mode 100644
index 0000000000..a6b4547ccb
--- /dev/null
+++ b/modules/vdzprintf-gnu-tests
@@ -0,0 +1,16 @@
+Files:
+tests/test-vdzprintf-gnu.sh
+tests/test-vdzprintf-gnu.c
+tests/test-fprintf-gnu.h
+tests/test-printf-gnu.output
+tests/infinity.h
+tests/macros.h
+
+Depends-on:
+stdint
+
+configure.ac:
+
+Makefile.am:
+TESTS += test-vdzprintf-gnu.sh
+check_PROGRAMS += test-vdzprintf-gnu
diff --git a/tests/test-fprintf-gnu.c b/tests/test-fprintf-gnu.c
index 12f1c90763..3c0b59d9b3 100644
--- a/tests/test-fprintf-gnu.c
+++ b/tests/test-fprintf-gnu.c
@@ -26,6 +26,7 @@
#include "macros.h"
+#define RETTYPE int
#include "test-fprintf-gnu.h"
int
diff --git a/tests/test-fprintf-gnu.h b/tests/test-fprintf-gnu.h
index f22ed39d02..ce6dc39557 100644
--- a/tests/test-fprintf-gnu.h
+++ b/tests/test-fprintf-gnu.h
@@ -1,4 +1,4 @@
-/* Test of POSIX and GNU compatible [v]fprintf() and vdprintf() functions.
+/* Test of POSIX and GNU compatible [v]fprintf() and vd[z]printf() functions.
Copyright (C) 2007-2024 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
@@ -17,7 +17,7 @@
/* Written by Bruno Haible <[email protected]>, 2023. */
static void
-test_function (int (*my_fprintf) (FILE *, const char *, ...))
+test_function (RETTYPE (*my_fprintf) (FILE *, const char *, ...))
{
/* Here we don't test output that may be platform dependent.
The bulk of the tests is done as part of the 'vasnprintf-posix' module. */
diff --git a/tests/test-vdprintf-gnu.c b/tests/test-vdprintf-gnu.c
index 5c0f0f3348..4a5f5ffef8 100644
--- a/tests/test-vdprintf-gnu.c
+++ b/tests/test-vdprintf-gnu.c
@@ -26,6 +26,7 @@
#include "macros.h"
+#define RETTYPE int
#include "test-fprintf-gnu.h"
static int
diff --git a/tests/test-vdzprintf-gnu.c b/tests/test-vdzprintf-gnu.c
new file mode 100644
index 0000000000..eb92b038bd
--- /dev/null
+++ b/tests/test-vdzprintf-gnu.c
@@ -0,0 +1,50 @@
+/* Test of POSIX and GNU compatible vdzprintf() function.
+ Copyright (C) 2007-2024 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 <[email protected]>, 2009. */
+
+#include <config.h>
+
+#include <stdio.h>
+
+#include <stdarg.h>
+#include <stddef.h>
+#include <stdint.h>
+#include <string.h>
+
+#include "macros.h"
+
+#define RETTYPE off64_t
+#include "test-fprintf-gnu.h"
+
+static off64_t
+my_fzprintf (FILE *fp, const char *format, ...)
+{
+ va_list args;
+ off64_t ret;
+
+ va_start (args, format);
+ ret = vdzprintf (fileno (fp), format, args);
+ va_end (args);
+ return ret;
+}
+
+int
+main (int argc, char *argv[])
+{
+ test_function (my_fzprintf);
+ return test_exit_status;
+}
diff --git a/tests/test-vdzprintf-gnu.sh b/tests/test-vdzprintf-gnu.sh
new file mode 100755
index 0000000000..058fb7d374
--- /dev/null
+++ b/tests/test-vdzprintf-gnu.sh
@@ -0,0 +1,16 @@
+#!/bin/sh
+
+tmpfiles=""
+trap 'rm -fr $tmpfiles' HUP INT QUIT TERM
+
+tmpfiles="$tmpfiles t-vdzprintf-gnu.tmp t-vdzprintf-gnu.out"
+${CHECKER} ./test-vdzprintf-gnu${EXEEXT} > t-vdzprintf-gnu.tmp || exit 1
+LC_ALL=C tr -d '\r' < t-vdzprintf-gnu.tmp > t-vdzprintf-gnu.out || exit 1
+
+: "${DIFF=diff}"
+${DIFF} "${srcdir}/test-printf-gnu.output" t-vdzprintf-gnu.out
+result=$?
+
+rm -fr $tmpfiles
+
+exit $result
diff --git a/tests/test-vfprintf-gnu.c b/tests/test-vfprintf-gnu.c
index 813992c93a..e8cc1c4a0b 100644
--- a/tests/test-vfprintf-gnu.c
+++ b/tests/test-vfprintf-gnu.c
@@ -26,6 +26,7 @@
#include "macros.h"
+#define RETTYPE int
#include "test-fprintf-gnu.h"
static int
--
2.34.1
>From 1af916894f8331a5d0543dc212927476cf107d92 Mon Sep 17 00:00:00 2001
From: Bruno Haible <[email protected]>
Date: Sun, 30 Jun 2024 17:32:14 +0200
Subject: [PATCH 11/12] dzprintf-gnu: New module.
* modules/dzprintf-gnu: New file.
---
ChangeLog | 5 +++++
modules/dzprintf-gnu | 23 +++++++++++++++++++++++
2 files changed, 28 insertions(+)
create mode 100644 modules/dzprintf-gnu
diff --git a/ChangeLog b/ChangeLog
index 03746bb590..f8de098bca 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2024-06-30 Bruno Haible <[email protected]>
+
+ dzprintf-gnu: New module.
+ * modules/dzprintf-gnu: New file.
+
2024-06-30 Bruno Haible <[email protected]>
vdzprintf-gnu: Add tests.
diff --git a/modules/dzprintf-gnu b/modules/dzprintf-gnu
new file mode 100644
index 0000000000..e8d6ab8dcb
--- /dev/null
+++ b/modules/dzprintf-gnu
@@ -0,0 +1,23 @@
+Description:
+dzprintf() function
+with POSIX and GNU compatible format string interpretation
+
+Files:
+
+Depends-on:
+dzprintf-posix
+mixin/printf-gnu
+
+configure.ac:
+gl_PREREQ_VASNPRINTF_WITH_GNU_EXTRAS
+
+Makefile.am:
+
+Include:
+<stdio.h>
+
+License:
+LGPL
+
+Maintainer:
+all
--
2.34.1
>From e448eb14bfc259dddb9f1368bff2dff166d9be91 Mon Sep 17 00:00:00 2001
From: Bruno Haible <[email protected]>
Date: Sun, 30 Jun 2024 17:43:45 +0200
Subject: [PATCH 12/12] dzprintf-gnu: Add tests.
* tests/test-dprintf-gnu.h: New file, extracted from
tests/test-dprintf-gnu.c.
* tests/test-dprintf-gnu.c: Include it.
(test_function): Remove function.
* modules/dprintf-gnu-tests (Files): Add it.
* tests/test-dzprintf-gnu.c: New file, based on
tests/test-dprintf-gnu.c.
* tests/test-dzprintf-gnu.sh: New file, based on
tests/test-dprintf-gnu.sh.
* modules/dzprintf-gnu-tests: New file.
---
ChangeLog | 12 ++++++
modules/dprintf-gnu-tests | 1 +
modules/dzprintf-gnu-tests | 15 +++++++
tests/test-dprintf-gnu.c | 65 +-----------------------------
tests/test-dprintf-gnu.h | 81 ++++++++++++++++++++++++++++++++++++++
tests/test-dzprintf-gnu.c | 36 +++++++++++++++++
tests/test-dzprintf-gnu.sh | 16 ++++++++
7 files changed, 163 insertions(+), 63 deletions(-)
create mode 100644 modules/dzprintf-gnu-tests
create mode 100644 tests/test-dprintf-gnu.h
create mode 100644 tests/test-dzprintf-gnu.c
create mode 100755 tests/test-dzprintf-gnu.sh
diff --git a/ChangeLog b/ChangeLog
index f8de098bca..a1c3732254 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,17 @@
2024-06-30 Bruno Haible <[email protected]>
+ dzprintf-gnu: Add tests.
+ * tests/test-dprintf-gnu.h: New file, extracted from
+ tests/test-dprintf-gnu.c.
+ * tests/test-dprintf-gnu.c: Include it.
+ (test_function): Remove function.
+ * modules/dprintf-gnu-tests (Files): Add it.
+ * tests/test-dzprintf-gnu.c: New file, based on
+ tests/test-dprintf-gnu.c.
+ * tests/test-dzprintf-gnu.sh: New file, based on
+ tests/test-dprintf-gnu.sh.
+ * modules/dzprintf-gnu-tests: New file.
+
dzprintf-gnu: New module.
* modules/dzprintf-gnu: New file.
diff --git a/modules/dprintf-gnu-tests b/modules/dprintf-gnu-tests
index 176d64c10c..d76b14719a 100644
--- a/modules/dprintf-gnu-tests
+++ b/modules/dprintf-gnu-tests
@@ -1,6 +1,7 @@
Files:
tests/test-dprintf-gnu.sh
tests/test-dprintf-gnu.c
+tests/test-dprintf-gnu.h
tests/test-printf-gnu.output
tests/macros.h
diff --git a/modules/dzprintf-gnu-tests b/modules/dzprintf-gnu-tests
new file mode 100644
index 0000000000..51d462bb47
--- /dev/null
+++ b/modules/dzprintf-gnu-tests
@@ -0,0 +1,15 @@
+Files:
+tests/test-dzprintf-gnu.sh
+tests/test-dzprintf-gnu.c
+tests/test-dprintf-gnu.h
+tests/test-printf-gnu.output
+tests/macros.h
+
+Depends-on:
+stdint
+
+configure.ac:
+
+Makefile.am:
+TESTS += test-dzprintf-gnu.sh
+check_PROGRAMS += test-dzprintf-gnu
diff --git a/tests/test-dprintf-gnu.c b/tests/test-dprintf-gnu.c
index 9f59c1cafd..497f262a03 100644
--- a/tests/test-dprintf-gnu.c
+++ b/tests/test-dprintf-gnu.c
@@ -25,69 +25,8 @@
#include "macros.h"
-static void
-test_function (int (*my_dprintf) (int, const char *, ...))
-{
- /* Here we don't test output that may be platform dependent.
- The bulk of the tests is done as part of the 'vasnprintf-posix' module. */
-
- /* Test the support of the 'B' conversion specifier for binary output of
- integers. */
-
- /* Zero. */
- my_dprintf (fileno (stdout), "%B %d\n", 0, 33, 44, 55);
-
- /* A positive number. */
- my_dprintf (fileno (stdout), "%B %d\n", 12345, 33, 44, 55);
-
- /* A large positive number. */
- my_dprintf (fileno (stdout), "%B %d\n", 0xFFFFFFFEU, 33, 44, 55);
-
- /* Width. */
- my_dprintf (fileno (stdout), "%20B %d\n", 12345, 33, 44, 55);
-
- /* Width given as argument. */
- my_dprintf (fileno (stdout), "%*B %d\n", 20, 12345, 33, 44, 55);
-
- /* Negative width given as argument (cf. FLAG_LEFT below). */
- my_dprintf (fileno (stdout), "%*B %d\n", -20, 12345, 33, 44, 55);
-
- /* Precision. */
- my_dprintf (fileno (stdout), "%.20B %d\n", 12345, 33, 44, 55);
-
- /* Zero precision and a positive number. */
- my_dprintf (fileno (stdout), "%.0B %d\n", 12345, 33, 44, 55);
-
- /* Zero precision and a zero number. */
- my_dprintf (fileno (stdout), "%.0B %d\n", 0, 33, 44, 55);
-
- /* Width and precision. */
- my_dprintf (fileno (stdout), "%25.20B %d\n", 12345, 33, 44, 55);
-
- /* FLAG_LEFT. */
- my_dprintf (fileno (stdout), "%-20B %d\n", 12345, 33, 44, 55);
-
- /* FLAG_ALT with zero. */
- my_dprintf (fileno (stdout), "%#B %d\n", 0, 33, 44, 55);
-
- /* FLAG_ALT with a positive number. */
- my_dprintf (fileno (stdout), "%#B %d\n", 12345, 33, 44, 55);
-
- /* FLAG_ALT with a positive number and width. */
- my_dprintf (fileno (stdout), "%#20B %d\n", 12345, 33, 44, 55);
-
- /* FLAG_ALT with a positive number and padding. */
- my_dprintf (fileno (stdout), "%0#20B %d\n", 12345, 33, 44, 55);
-
- /* FLAG_ALT with a positive number and precision. */
- my_dprintf (fileno (stdout), "%0#.20B %d\n", 12345, 33, 44, 55);
-
- /* FLAG_ALT with a positive number and width and precision. */
- my_dprintf (fileno (stdout), "%#25.20B %d\n", 12345, 33, 44, 55);
-
- /* FLAG_ALT with a zero precision and a zero number. */
- my_dprintf (fileno (stdout), "%#.0B %d\n", 0, 33, 44, 55);
-}
+#define RETTYPE int
+#include "test-dprintf-gnu.h"
int
main (int argc, char *argv[])
diff --git a/tests/test-dprintf-gnu.h b/tests/test-dprintf-gnu.h
new file mode 100644
index 0000000000..deeabdaaa2
--- /dev/null
+++ b/tests/test-dprintf-gnu.h
@@ -0,0 +1,81 @@
+/* Test of POSIX and GNU compatible d[z]printf() function.
+ Copyright (C) 2007-2024 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 <[email protected]>, 2023. */
+
+static void
+test_function (RETTYPE (*my_dprintf) (int, const char *, ...))
+{
+ /* Here we don't test output that may be platform dependent.
+ The bulk of the tests is done as part of the 'vasnprintf-posix' module. */
+
+ /* Test the support of the 'B' conversion specifier for binary output of
+ integers. */
+
+ /* Zero. */
+ my_dprintf (fileno (stdout), "%B %d\n", 0, 33, 44, 55);
+
+ /* A positive number. */
+ my_dprintf (fileno (stdout), "%B %d\n", 12345, 33, 44, 55);
+
+ /* A large positive number. */
+ my_dprintf (fileno (stdout), "%B %d\n", 0xFFFFFFFEU, 33, 44, 55);
+
+ /* Width. */
+ my_dprintf (fileno (stdout), "%20B %d\n", 12345, 33, 44, 55);
+
+ /* Width given as argument. */
+ my_dprintf (fileno (stdout), "%*B %d\n", 20, 12345, 33, 44, 55);
+
+ /* Negative width given as argument (cf. FLAG_LEFT below). */
+ my_dprintf (fileno (stdout), "%*B %d\n", -20, 12345, 33, 44, 55);
+
+ /* Precision. */
+ my_dprintf (fileno (stdout), "%.20B %d\n", 12345, 33, 44, 55);
+
+ /* Zero precision and a positive number. */
+ my_dprintf (fileno (stdout), "%.0B %d\n", 12345, 33, 44, 55);
+
+ /* Zero precision and a zero number. */
+ my_dprintf (fileno (stdout), "%.0B %d\n", 0, 33, 44, 55);
+
+ /* Width and precision. */
+ my_dprintf (fileno (stdout), "%25.20B %d\n", 12345, 33, 44, 55);
+
+ /* FLAG_LEFT. */
+ my_dprintf (fileno (stdout), "%-20B %d\n", 12345, 33, 44, 55);
+
+ /* FLAG_ALT with zero. */
+ my_dprintf (fileno (stdout), "%#B %d\n", 0, 33, 44, 55);
+
+ /* FLAG_ALT with a positive number. */
+ my_dprintf (fileno (stdout), "%#B %d\n", 12345, 33, 44, 55);
+
+ /* FLAG_ALT with a positive number and width. */
+ my_dprintf (fileno (stdout), "%#20B %d\n", 12345, 33, 44, 55);
+
+ /* FLAG_ALT with a positive number and padding. */
+ my_dprintf (fileno (stdout), "%0#20B %d\n", 12345, 33, 44, 55);
+
+ /* FLAG_ALT with a positive number and precision. */
+ my_dprintf (fileno (stdout), "%0#.20B %d\n", 12345, 33, 44, 55);
+
+ /* FLAG_ALT with a positive number and width and precision. */
+ my_dprintf (fileno (stdout), "%#25.20B %d\n", 12345, 33, 44, 55);
+
+ /* FLAG_ALT with a zero precision and a zero number. */
+ my_dprintf (fileno (stdout), "%#.0B %d\n", 0, 33, 44, 55);
+}
diff --git a/tests/test-dzprintf-gnu.c b/tests/test-dzprintf-gnu.c
new file mode 100644
index 0000000000..b324bf9332
--- /dev/null
+++ b/tests/test-dzprintf-gnu.c
@@ -0,0 +1,36 @@
+/* Test of POSIX and GNU compatible dzprintf() function.
+ Copyright (C) 2007-2024 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 <[email protected]>, 2023. */
+
+#include <config.h>
+
+#include <stdio.h>
+
+#include <stddef.h>
+#include <string.h>
+
+#include "macros.h"
+
+#define RETTYPE off64_t
+#include "test-dprintf-gnu.h"
+
+int
+main (int argc, char *argv[])
+{
+ test_function (dzprintf);
+ return test_exit_status;
+}
diff --git a/tests/test-dzprintf-gnu.sh b/tests/test-dzprintf-gnu.sh
new file mode 100755
index 0000000000..b7753da4d0
--- /dev/null
+++ b/tests/test-dzprintf-gnu.sh
@@ -0,0 +1,16 @@
+#!/bin/sh
+
+tmpfiles=""
+trap 'rm -fr $tmpfiles' HUP INT QUIT TERM
+
+tmpfiles="$tmpfiles t-dzprintf-gnu.tmp t-dzprintf-gnu.out"
+${CHECKER} ./test-dzprintf-gnu${EXEEXT} > t-dzprintf-gnu.tmp || exit 1
+LC_ALL=C tr -d '\r' < t-dzprintf-gnu.tmp > t-dzprintf-gnu.out || exit 1
+
+: "${DIFF=diff}"
+${DIFF} "${srcdir}/test-printf-gnu.output" t-dzprintf-gnu.out
+result=$?
+
+rm -fr $tmpfiles
+
+exit $result
--
2.34.1