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

ChangeLog
lib/dprintf.c
lib/stdio.in.h
modules/dprintf

index 9b8a2052041cd161bc6dba400e7780777447c225..ddc7cb61c419d1c8242a587601505193c99c4958 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
 2024-06-30  Bruno Haible  <bruno@clisp.org>
 
+       dprintf: Use vdzprintf.
+       * lib/stdio.in.h (dprintf): Add specification.
+       * lib/dprintf.c: Don't include <stdlib.h>, 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.
index 70d359c3452bf144ad11b099932d706cba40b76a..a543d5c0368eb2739a585dfedc585ef388208930 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
 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;
 }
index 5fac912db2bd4ff9a19577148411e2cd2203c6a3..acbe14cc419d87de87b217d629f2b3f13fc0a85d 100644 (file)
@@ -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
index 653cb9380c2be768b4eba17b76bfbeb430f8e0ee..1e9d208df918bb1521c7ff053f5ccc848004e581 100644 (file)
@@ -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: