]> Savannah Git Hosting - gnulib.git/commitdiff
vdprintf: Use vdzprintf.
authorBruno Haible <bruno@clisp.org>
Sun, 30 Jun 2024 15:15:28 +0000 (17:15 +0200)
committerBruno Haible <bruno@clisp.org>
Sun, 30 Jun 2024 15:15:40 +0000 (17:15 +0200)
* lib/stdio.in.h (vdprintf): Add specification.
* lib/vdprintf.c: Don't include <stdlib.h>, 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
lib/stdio.in.h
lib/vdprintf.c
modules/vdprintf

index c75cbe10f11932ca57cfe2d5ce8bc8d568a5e7af..72ecdad3d5b34775e7b143a975237f94a4e1720b 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
 2024-06-30  Bruno Haible  <bruno@clisp.org>
 
+       vdprintf: Use vdzprintf.
+       * lib/stdio.in.h (vdprintf): Add specification.
+       * lib/vdprintf.c: Don't include <stdlib.h>, 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.
index 52dc8f30ba9d1c08189493589102ba021d603cde..03e4cf9ca6f1e4bd47aa8ba0090b4237beb8d1f4 100644 (file)
@@ -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
index 571e74f90ae976e3eb985566c2e9e809c6fa429a..263baf9aa2c2a4d1e97b62d857bfef028545995e 100644 (file)
 #include <errno.h>
 #include <limits.h>
 #include <stdarg.h>
-#include <stdlib.h>
 
-#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;
 }
index 87192a3fdc68807c33a368c59338491d21c60a71..b09dbd748e6de6cd6336de577c87b7c6a925f6b0 100644 (file)
@@ -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: