From: Bruno Haible Date: Sun, 30 Jun 2024 16:45:25 +0000 (+0200) Subject: vfprintf-posix: Use vfzprintf. X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=8a3988719830bafc59c4b36c58348ea32bd6c1ce;p=gnulib.git vfprintf-posix: Use vfzprintf. * lib/stdio.in.h (vfprintf): Add specification. * lib/vfprintf.c: Don't include , vasnprintf.h. Include intprops.h. (vfprintf): Implement based on vfzprintf. * modules/vfprintf-posix (Depends-on): Add vfzprintf, intprops. Remove vasnprintf, free-posix. --- diff --git a/ChangeLog b/ChangeLog index bb0e4aa50d..51af63d1b8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,13 @@ 2024-06-30 Bruno Haible + vfprintf-posix: Use vfzprintf. + * lib/stdio.in.h (vfprintf): Add specification. + * lib/vfprintf.c: Don't include , vasnprintf.h. + Include intprops.h. + (vfprintf): Implement based on vfzprintf. + * modules/vfprintf-posix (Depends-on): Add vfzprintf, intprops. Remove + vasnprintf, free-posix. + vfzprintf: New module. * lib/stdio.in.h (vfzprintf): New declaration. * lib/vfzprintf.c: New file, based on lib/vfprintf.c and diff --git a/lib/stdio.in.h b/lib/stdio.in.h index e4a0997919..8802e87832 100644 --- a/lib/stdio.in.h +++ b/lib/stdio.in.h @@ -1794,6 +1794,9 @@ _GL_CXXALIAS_SYS (vfzprintf, off64_t, #endif #if @GNULIB_VFPRINTF_POSIX@ || @GNULIB_VFPRINTF@ +/* Prints formatted output to stream FP. + Returns the number of bytes written to the stream. Upon failure, + returns a negative value with the stream's error indicator set. */ # if (@GNULIB_VFPRINTF_POSIX@ && @REPLACE_VFPRINTF@) \ || (@GNULIB_VFPRINTF@ && @REPLACE_STDIO_WRITE_FUNCS@ && (@GNULIB_STDIO_H_NONBLOCKING@ || @GNULIB_STDIO_H_SIGPIPE@)) # if !(defined __cplusplus && defined GNULIB_NAMESPACE) diff --git a/lib/vfprintf.c b/lib/vfprintf.c index 4cd5cbdb68..5a87350b59 100644 --- a/lib/vfprintf.c +++ b/lib/vfprintf.c @@ -24,47 +24,21 @@ #include #include #include -#include #include "fseterr.h" -#include "vasnprintf.h" +#include "intprops.h" -/* Print formatted output to the stream FP. - Return string length of formatted string. On error, return a negative - value. */ int vfprintf (FILE *fp, const char *format, va_list args) { - char buf[2000]; - char *output; - size_t len; - size_t lenbuf = sizeof (buf); + off64_t ret = vfzprintf (fp, format, args); - output = vasnprintf (buf, &lenbuf, format, args); - len = lenbuf; - - if (!output) + if (TYPE_MAXIMUM (off64_t) > INT_MAX && ret > INT_MAX) { fseterr (fp); - return -1; - } - - if (fwrite (output, 1, len, fp) < len) - { - if (output != buf) - free (output); - return -1; - } - - if (output != buf) - free (output); - - if (len > INT_MAX) - { errno = EOVERFLOW; - fseterr (fp); return -1; } - return len; + return ret; } diff --git a/modules/vfprintf-posix b/modules/vfprintf-posix index 3bc350d98b..aec763b2e3 100644 --- a/modules/vfprintf-posix +++ b/modules/vfprintf-posix @@ -18,10 +18,10 @@ stdio nocrash printf-safe multiarch -free-posix [test $REPLACE_VFPRINTF = 1] -fseterr [test $REPLACE_VFPRINTF = 1] -vasnprintf [test $REPLACE_VFPRINTF = 1] +vfzprintf [test $REPLACE_VFPRINTF = 1] mixin/printf-posix [test $REPLACE_VFPRINTF = 1] +intprops [test $REPLACE_VFPRINTF = 1] +fseterr [test $REPLACE_VFPRINTF = 1] errno [test $REPLACE_VFPRINTF = 1] configure.ac: