1 /* Copyright 2005, 2007 Shaun Jackman
2 * Permission to use, copy, modify, and distribute this software
3 * is freely granted, provided that this notice is preserved.
4 */
5 /* doc in dprintf.c */
6
7 #define _DEFAULT_SOURCE
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <unistd.h>
11 #include <stdarg.h>
12 #include "local.h"
13
14 int
vdprintf(int fd,const char * __restrict format,va_list ap)15 vdprintf (
16 int fd,
17 const char *__restrict format,
18 va_list ap)
19 {
20 char *p;
21 char buf[512];
22 size_t n = sizeof buf;
23
24 _REENT_SMALL_CHECK_INIT (ptr);
25 p = vasnprintf ( buf, &n, format, ap);
26 if (!p)
27 return -1;
28 n = write (fd, p, n);
29 if (p != buf)
30 free (p);
31 return n;
32 }
33
34 #ifdef _NANO_FORMATTED_IO
35 int
36 vdiprintf (int, const char *, __VALIST)
37 _ATTRIBUTE ((__alias__("vdprintf")));
38 #endif
39