From 439f2f253413a33c973f8e139514b5aa03713d34 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sun, 30 Jun 2024 20:00:58 +0200 Subject: [PATCH] vzprintf: New module. * lib/stdio.in.h (vzprintf): New declaration. * lib/vzprintf.c: New file, based on lib/vprintf.c. * m4/stdio_h.m4 (gl_STDIO_H_REQUIRE_DEFAULTS): Initialize GNULIB_VZPRINTF. * modules/stdio (Makefile.am): Substitute GNULIB_VZPRINTF. * modules/vzprintf: New file. --- ChangeLog | 10 ++++++++++ lib/stdio.in.h | 15 +++++++++++++++ lib/vzprintf.c | 30 ++++++++++++++++++++++++++++++ m4/stdio_h.m4 | 3 ++- modules/stdio | 1 + modules/vzprintf | 25 +++++++++++++++++++++++++ 6 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 lib/vzprintf.c create mode 100644 modules/vzprintf diff --git a/ChangeLog b/ChangeLog index 8492ed8314..755b3d4630 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2024-06-30 Bruno Haible + + vzprintf: New module. + * lib/stdio.in.h (vzprintf): New declaration. + * lib/vzprintf.c: New file, based on lib/vprintf.c. + * m4/stdio_h.m4 (gl_STDIO_H_REQUIRE_DEFAULTS): Initialize + GNULIB_VZPRINTF. + * modules/stdio (Makefile.am): Substitute GNULIB_VZPRINTF. + * modules/vzprintf: New file. + 2024-06-30 Bruno Haible fprintf-posix: Use vfzprintf. diff --git a/lib/stdio.in.h b/lib/stdio.in.h index 1c48954d81..9ecca6a0d1 100644 --- a/lib/stdio.in.h +++ b/lib/stdio.in.h @@ -1884,6 +1884,21 @@ _GL_CXXALIASWARN (vfscanf); # endif #endif +#if @GNULIB_VZPRINTF@ +/* 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 (vzprintf, off64_t, (const char *restrict format, va_list args) + _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (1, 0) + _GL_ARG_NONNULL ((1))); +_GL_CXXALIAS_SYS (vzprintf, off64_t, + (const char *restrict format, va_list args)); +#endif + #if @GNULIB_VPRINTF_POSIX@ || @GNULIB_VPRINTF@ # if (@GNULIB_VPRINTF_POSIX@ && @REPLACE_VPRINTF@) \ || (@GNULIB_VPRINTF@ && @REPLACE_STDIO_WRITE_FUNCS@ && (@GNULIB_STDIO_H_NONBLOCKING@ || @GNULIB_STDIO_H_SIGPIPE@)) diff --git a/lib/vzprintf.c b/lib/vzprintf.c new file mode 100644 index 0000000000..5a8eef2d45 --- /dev/null +++ b/lib/vzprintf.c @@ -0,0 +1,30 @@ +/* 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 . */ + +#ifdef HAVE_CONFIG_H +# include +#endif + +/* Specification. */ +#include + +#include + +off64_t +vzprintf (const char *format, va_list args) +{ + return vfzprintf (stdout, format, args); +} diff --git a/m4/stdio_h.m4 b/m4/stdio_h.m4 index 542280100a..a0e1c3caed 100644 --- a/m4/stdio_h.m4 +++ b/m4/stdio_h.m4 @@ -1,5 +1,5 @@ # stdio_h.m4 -# serial 73 +# serial 74 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, @@ -196,6 +196,7 @@ AC_DEFUN([gl_STDIO_H_REQUIRE_DEFAULTS], 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_VZPRINTF]) 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 a366b51a85..69ab95dd37 100644 --- a/modules/stdio +++ b/modules/stdio @@ -131,6 +131,7 @@ stdio.h: stdio.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) -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_VZPRINTF''@/$(GNULIB_VZPRINTF)/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/vzprintf b/modules/vzprintf new file mode 100644 index 0000000000..be88f208c2 --- /dev/null +++ b/modules/vzprintf @@ -0,0 +1,25 @@ +Description: +vzprintf() function: print formatted output (without INT_MAX limitation) +to standard output + +Files: +lib/vzprintf.c + +Depends-on: +stdio +vfzprintf + +configure.ac: +gl_STDIO_MODULE_INDICATOR([vzprintf]) + +Makefile.am: +lib_SOURCES += vzprintf.c + +Include: + + +License: +LGPL + +Maintainer: +all -- 2.39.5