From: Bruno Haible Date: Sun, 30 Jun 2024 15:18:35 +0000 (+0200) Subject: dprintf: Use vdzprintf. X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=f320c3a588a5509993cc57bf9a29afdfd6c064e0;p=gnulib.git dprintf: Use vdzprintf. * lib/stdio.in.h (dprintf): Add specification. * lib/dprintf.c: Don't include , full-write.h, vasnprintf.h. Include intprops.h. (dprintf): Implement based on vdzprintf. * modules/dprintf (Depends-on): Add vdzprintf, intprops. Remove vasnprintf, free-posix, full-write. --- diff --git a/ChangeLog b/ChangeLog index 9b8a205204..ddc7cb61c4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,13 @@ 2024-06-30 Bruno Haible + dprintf: Use vdzprintf. + * lib/stdio.in.h (dprintf): Add specification. + * lib/dprintf.c: Don't include , full-write.h, vasnprintf.h. + Include intprops.h. + (dprintf): Implement based on vdzprintf. + * modules/dprintf (Depends-on): Add vdzprintf, intprops. Remove + vasnprintf, free-posix, full-write. + dzprintf: New module. * lib/stdio.in.h (dzprintf): New declaration. * lib/dzprintf.c: New file, based on lib/vdzprintf.c. diff --git a/lib/dprintf.c b/lib/dprintf.c index 70d359c345..a543d5c036 100644 --- a/lib/dprintf.c +++ b/lib/dprintf.c @@ -24,43 +24,24 @@ #include #include #include -#include -#include "full-write.h" -#include "vasnprintf.h" +#include "intprops.h" int dprintf (int fd, const char *format, ...) { - char buf[2000]; - char *output; - size_t len; - size_t lenbuf = sizeof (buf); va_list args; + off64_t ret; va_start (args, format); - output = vasnprintf (buf, &lenbuf, format, args); - len = lenbuf; + ret = vdzprintf (fd, format, args); va_end (args); - 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/lib/stdio.in.h b/lib/stdio.in.h index 5fac912db2..acbe14cc41 100644 --- a/lib/stdio.in.h +++ b/lib/stdio.in.h @@ -297,6 +297,9 @@ _GL_CXXALIAS_SYS (dzprintf, off64_t, #endif #if @GNULIB_DPRINTF@ +/* 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_DPRINTF@ # if !(defined __cplusplus && defined GNULIB_NAMESPACE) # define dprintf rpl_dprintf diff --git a/modules/dprintf b/modules/dprintf index 653cb9380c..1e9d208df9 100644 --- a/modules/dprintf +++ b/modules/dprintf @@ -7,9 +7,8 @@ m4/dprintf.m4 Depends-on: stdio -vasnprintf [test $ac_cv_func_dprintf = no || test $REPLACE_DPRINTF = 1] -free-posix [test $ac_cv_func_dprintf = no || test $REPLACE_DPRINTF = 1] -full-write [test $ac_cv_func_dprintf = no || test $REPLACE_DPRINTF = 1] +vdzprintf [test $ac_cv_func_dprintf = no || test $REPLACE_DPRINTF = 1] +intprops [test $ac_cv_func_dprintf = no || test $REPLACE_DPRINTF = 1] errno [test $ac_cv_func_dprintf = no || test $REPLACE_DPRINTF = 1] configure.ac: