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 <_ansi.h>
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <unistd.h>
12 #include <stdarg.h>
13 #include "local.h"
14
15 int
vdiprintf(int fd,const char * format,va_list ap)16 vdiprintf (
17 int fd,
18 const char *format,
19 va_list ap)
20 {
21 char *p;
22 char buf[512];
23 size_t n = sizeof buf;
24
25 _REENT_SMALL_CHECK_INIT (ptr);
26 p = vasniprintf ( buf, &n, format, ap);
27 if (!p)
28 return -1;
29 n = write (fd, p, n);
30 if (p != buf)
31 free (p);
32 return n;
33 }
34