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