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