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 diprintf.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
vdiprintf(int fd,const char * format,va_list ap)15 vdiprintf (
16        int fd,
17        const char *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 = vasniprintf ( 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