]> Savannah Git Hosting - gnulib.git/commitdiff
zprintf: New module.
authorBruno Haible <bruno@clisp.org>
Sun, 30 Jun 2024 18:58:29 +0000 (20:58 +0200)
committerBruno Haible <bruno@clisp.org>
Sun, 30 Jun 2024 20:32:52 +0000 (22:32 +0200)
* lib/stdio.in.h (zprintf): New declaration.
* lib/zprintf.c: New file, based on lib/vzprintf.c.
* m4/stdio_h.m4 (gl_STDIO_H_REQUIRE_DEFAULTS): Initialize
GNULIB_ZPRINTF.
* modules/stdio (Makefile.am): Substitute GNULIB_ZPRINTF.
* modules/zprintf: New file.

ChangeLog
lib/stdio.in.h
lib/zprintf.c [new file with mode: 0644]
m4/stdio_h.m4
modules/stdio
modules/zprintf [new file with mode: 0644]

index 62041cd616bd6d5d64bce262330d12e6c4b01f28..3b6f777e85dd7d8be3bcc37da14432109bddc9d8 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2024-06-30  Bruno Haible  <bruno@clisp.org>
+
+       zprintf: New module.
+       * lib/stdio.in.h (zprintf): New declaration.
+       * lib/zprintf.c: New file, based on lib/vzprintf.c.
+       * m4/stdio_h.m4 (gl_STDIO_H_REQUIRE_DEFAULTS): Initialize
+       GNULIB_ZPRINTF.
+       * modules/stdio (Makefile.am): Substitute GNULIB_ZPRINTF.
+       * modules/zprintf: New file.
+
 2024-06-30  Bruno Haible  <bruno@clisp.org>
 
        vprintf-posix: Document properly.
index 51876b24550cc5a6588ea477e29b624a471b3886..013c7a4ad186767325dda12c86c73419a30110b7 100644 (file)
@@ -1265,6 +1265,20 @@ _GL_WARN_ON_USE (popen, "popen is buggy on some platforms - "
 # endif
 #endif
 
+#if @GNULIB_ZPRINTF@
+/* Prints formatted output to standard output.
+   Returns the number of bytes written to standard output.  Upon failure,
+   returns -1 with stdout's error indicator set.
+   Failure cause 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 causes are ENOMEM
+   and the possible failure causes from fwrite().  */
+_GL_FUNCDECL_SYS (zprintf, off64_t, (const char *restrict format, ...)
+                                    _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (1, 2)
+                                    _GL_ARG_NONNULL ((1)));
+_GL_CXXALIAS_SYS (zprintf, off64_t, (const char *restrict format, ...));
+#endif
+
 #if @GNULIB_PRINTF_POSIX@ || @GNULIB_PRINTF@
 # if (@GNULIB_PRINTF_POSIX@ && @REPLACE_PRINTF@) \
      || (@GNULIB_PRINTF@ && @REPLACE_STDIO_WRITE_FUNCS@ && (@GNULIB_STDIO_H_NONBLOCKING@ || @GNULIB_STDIO_H_SIGPIPE@))
diff --git a/lib/zprintf.c b/lib/zprintf.c
new file mode 100644 (file)
index 0000000..b5a383a
--- /dev/null
@@ -0,0 +1,37 @@
+/* Formatted output to standard output.
+   Copyright (C) 2007, 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 <stdarg.h>
+
+off64_t
+zprintf (const char *format, ...)
+{
+  va_list args;
+  off64_t ret;
+
+  va_start (args, format);
+  ret = vfzprintf (stdout, format, args);
+  va_end (args);
+
+  return ret;
+}
index a0e1c3caede1f1e4c417711bd4c538bca0cd0263..ec52ae92ff4c5a5e3169ca4b00c6419415beb702 100644 (file)
@@ -1,5 +1,5 @@
 # stdio_h.m4
-# serial 74
+# serial 75
 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,
@@ -197,6 +197,7 @@ AC_DEFUN([gl_STDIO_H_REQUIRE_DEFAULTS],
     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_VSPRINTF_POSIX])
     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_VSZPRINTF])
     gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_VZPRINTF])
+    gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_ZPRINTF])
     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])
index 69ab95dd37da7103d8e1b6614bb8b7bf9035a348..0e6b6e4d2112e77644e9238a9bc7fbbb0f670c79 100644 (file)
@@ -132,6 +132,7 @@ stdio.h: stdio.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H)
              -e 's/@''GNULIB_VSPRINTF_POSIX''@/$(GNULIB_VSPRINTF_POSIX)/g' \
              -e 's/@''GNULIB_VSZPRINTF''@/$(GNULIB_VSZPRINTF)/g' \
              -e 's/@''GNULIB_VZPRINTF''@/$(GNULIB_VZPRINTF)/g' \
+             -e 's/@''GNULIB_ZPRINTF''@/$(GNULIB_ZPRINTF)/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/zprintf b/modules/zprintf
new file mode 100644 (file)
index 0000000..d4acca6
--- /dev/null
@@ -0,0 +1,25 @@
+Description:
+zprintf() function: print formatted output (without INT_MAX limitation)
+to standard output
+
+Files:
+lib/zprintf.c
+
+Depends-on:
+stdio
+vfzprintf
+
+configure.ac:
+gl_STDIO_MODULE_INDICATOR([zprintf])
+
+Makefile.am:
+lib_SOURCES += zprintf.c
+
+Include:
+<stdio.h>
+
+License:
+LGPL
+
+Maintainer:
+all