* lib/stdio.in.h (obstack_zprintf, obstack_vzprintf): New declarations.
(obstack_printf, obstack_vprintf): Tweak comment.
* lib/obstack_printf.c: Parameterize.
(RESULT_TYPE, OBSTACK_PRINTF, OBSTACK_VPRINTF): New macros.
* lib/obstack_zprintf.c: New file.
* m4/stdio_h.m4 (gl_STDIO_H_REQUIRE_DEFAULTS): Initialize
GNULIB_OBSTACK_ZPRINTF.
* modules/stdio (Makefile.am): Substitute GNULIB_OBSTACK_ZPRINTF.
* modules/obstack-zprintf: New file.
+2024-06-22 Bruno Haible <bruno@clisp.org>
+
+ obstack-zprintf: New module.
+ * lib/stdio.in.h (obstack_zprintf, obstack_vzprintf): New declarations.
+ (obstack_printf, obstack_vprintf): Tweak comment.
+ * lib/obstack_printf.c: Parameterize.
+ (RESULT_TYPE, OBSTACK_PRINTF, OBSTACK_VPRINTF): New macros.
+ * lib/obstack_zprintf.c: New file.
+ * m4/stdio_h.m4 (gl_STDIO_H_REQUIRE_DEFAULTS): Initialize
+ GNULIB_OBSTACK_ZPRINTF.
+ * modules/stdio (Makefile.am): Substitute GNULIB_OBSTACK_ZPRINTF.
+ * modules/obstack-zprintf: New file.
+
2024-06-22 Bruno Haible <bruno@clisp.org>
physmem: Fix typo.
#include <stdarg.h>
#include <stdlib.h>
+#ifndef RESULT_TYPE
+# define RESULT_TYPE int
+# define OBSTACK_PRINTF obstack_printf
+# define OBSTACK_VPRINTF obstack_vprintf
+#endif
+
/* Grow an obstack with formatted output. Return the number of bytes
added to OBS. No trailing nul byte is added, and the object should
be closed with obstack_finish before use.
Upon memory allocation error, call obstack_alloc_failed_handler.
Upon other error, return -1. */
-int
-obstack_printf (struct obstack *obs, const char *format, ...)
+RESULT_TYPE
+OBSTACK_PRINTF (struct obstack *obs, const char *format, ...)
{
va_list args;
- int result;
+ RESULT_TYPE result;
va_start (args, format);
- result = obstack_vprintf (obs, format, args);
+ result = OBSTACK_VPRINTF (obs, format, args);
va_end (args);
return result;
}
Upon memory allocation error, call obstack_alloc_failed_handler.
Upon other error, return -1. */
-int
-obstack_vprintf (struct obstack *obs, const char *format, va_list args)
+RESULT_TYPE
+OBSTACK_VPRINTF (struct obstack *obs, const char *format, va_list args)
{
/* If we are close to the end of the current obstack chunk, use a
stack-allocated buffer and copy, to reduce the likelihood of a
--- /dev/null
+/* Formatted output to obstacks.
+ Copyright (C) 2008-2024 Free Software Foundation, Inc.
+
+ This file 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 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 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/>. */
+
+#define RESULT_TYPE ptrdiff_t
+#define OBSTACK_PRINTF obstack_zprintf
+#define OBSTACK_VPRINTF obstack_vzprintf
+#include "obstack_printf.c"
# endif
#endif
+#if @GNULIB_OBSTACK_ZPRINTF@
+struct obstack;
+/* Grows an obstack with formatted output. Returns the number of
+ bytes added to OBS. No trailing nul byte is added, and the
+ object should be closed with obstack_finish before use.
+ Upon memory allocation error, calls obstack_alloc_failed_handler.
+ Upon other error, 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 code is through
+ obstack_alloc_failed_handler. */
+_GL_FUNCDECL_SYS (obstack_zprintf, ptrdiff_t,
+ (struct obstack *obs, const char *format, ...)
+ _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (2, 3)
+ _GL_ARG_NONNULL ((1, 2)));
+_GL_CXXALIAS_SYS (obstack_zprintf, ptrdiff_t,
+ (struct obstack *obs, const char *format, ...));
+_GL_FUNCDECL_SYS (obstack_vzprintf, ptrdiff_t,
+ (struct obstack *obs, const char *format, va_list args)
+ _GL_ATTRIBUTE_FORMAT_PRINTF_STANDARD (2, 0)
+ _GL_ARG_NONNULL ((1, 2)));
+_GL_CXXALIAS_SYS (obstack_vzprintf, ptrdiff_t,
+ (struct obstack *obs, const char *format, va_list args));
+#endif
+
#if @GNULIB_OBSTACK_PRINTF@ || @GNULIB_OBSTACK_PRINTF_POSIX@
struct obstack;
-/* Grow an obstack with formatted output. Return the number of
+/* Grows an obstack with formatted output. Returns the number of
bytes added to OBS. No trailing nul byte is added, and the
- object should be closed with obstack_finish before use. Upon
- memory allocation error, call obstack_alloc_failed_handler. Upon
- other error, return -1. */
+ object should be closed with obstack_finish before use.
+ Upon memory allocation error, calls obstack_alloc_failed_handler.
+ Upon other error, returns -1. */
# if @REPLACE_OBSTACK_PRINTF@
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
# define obstack_printf rpl_obstack_printf
# stdio_h.m4
-# serial 68
+# serial 69
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,
gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_GETLINE])
gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_OBSTACK_PRINTF])
gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_OBSTACK_PRINTF_POSIX])
+ gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_OBSTACK_ZPRINTF])
gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_PCLOSE])
gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_PERROR])
gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_POPEN])
--- /dev/null
+Description:
+Formatted printing into an obstack (without INT_MAX limitation).
+
+Files:
+lib/obstack_zprintf.c
+lib/obstack_printf.c
+
+Depends-on:
+obstack
+stdio
+vasnprintf
+
+configure.ac:
+gl_STDIO_MODULE_INDICATOR([obstack-zprintf])
+
+Makefile.am:
+lib_SOURCES += obstack_zprintf.c
+
+Include:
+<stdio.h>
+
+License:
+GPL
+
+Maintainer:
+all
-e 's/@''GNULIB_GETLINE''@/$(GNULIB_GETLINE)/g' \
-e 's/@''GNULIB_OBSTACK_PRINTF''@/$(GNULIB_OBSTACK_PRINTF)/g' \
-e 's/@''GNULIB_OBSTACK_PRINTF_POSIX''@/$(GNULIB_OBSTACK_PRINTF_POSIX)/g' \
+ -e 's/@''GNULIB_OBSTACK_ZPRINTF''@/$(GNULIB_OBSTACK_ZPRINTF)/g' \
-e 's/@''GNULIB_PCLOSE''@/$(GNULIB_PCLOSE)/g' \
-e 's/@''GNULIB_PERROR''@/$(GNULIB_PERROR)/g' \
-e 's/@''GNULIB_POPEN''@/$(GNULIB_POPEN)/g' \