]> Savannah Git Hosting - gnulib.git/commitdiff
vfprintf-posix: Use vfzprintf.
authorBruno Haible <bruno@clisp.org>
Sun, 30 Jun 2024 16:45:25 +0000 (18:45 +0200)
committerBruno Haible <bruno@clisp.org>
Sun, 30 Jun 2024 17:01:35 +0000 (19:01 +0200)
* lib/stdio.in.h (vfprintf): Add specification.
* lib/vfprintf.c: Don't include <stdlib.h>, vasnprintf.h.
Include intprops.h.
(vfprintf): Implement based on vfzprintf.
* modules/vfprintf-posix (Depends-on): Add vfzprintf, intprops. Remove
vasnprintf, free-posix.

ChangeLog
lib/stdio.in.h
lib/vfprintf.c
modules/vfprintf-posix

index bb0e4aa50da84ba997f1618a190dcc4026dd781f..51af63d1b8ea67ab87fd25ac957040c521561b46 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
 2024-06-30  Bruno Haible  <bruno@clisp.org>
 
+       vfprintf-posix: Use vfzprintf.
+       * lib/stdio.in.h (vfprintf): Add specification.
+       * lib/vfprintf.c: Don't include <stdlib.h>, 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
index e4a09979199fd74e486948a68b90f79d64a20263..8802e878327072cb18cc14a13392855808cfe0d7 100644 (file)
@@ -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)
index 4cd5cbdb68b8c2a90498961845a477c93b662cf6..5a87350b59e65a8cf7b31e89ea62695b33686d36 100644 (file)
 #include <errno.h>
 #include <limits.h>
 #include <stdarg.h>
-#include <stdlib.h>
 
 #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;
 }
index 3bc350d98b156ff7914a06e9eba6d6ec0d6c730d..aec763b2e3240d19773e129abd71d01b862a29b8 100644 (file)
@@ -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: