* 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.
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
#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)
#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;
}
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: