From 3a40fb5e8dae23beaf54bb104c3e6d916881e0a0 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sun, 30 Jun 2024 17:15:28 +0200 Subject: [PATCH] vdprintf: Use vdzprintf. * lib/stdio.in.h (vdprintf): Add specification. * lib/vdprintf.c: Don't include , 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 + vdprintf: Use vdzprintf. + * lib/stdio.in.h (vdprintf): Add specification. + * lib/vdprintf.c: Don't include , 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 #include #include -#include -#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.39.5