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 #include <_ansi.h>
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <unistd.h>
11 #include <stdarg.h>
12 #include "local.h"
13 
14 int
_vdprintf_r(struct _reent * ptr,int fd,const char * __restrict format,va_list ap)15 _vdprintf_r (struct _reent *ptr,
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_r (ptr, 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_r (struct _reent *, int, const char *, __VALIST)
37        _ATTRIBUTE ((__alias__("_vdprintf_r")));
38 #endif
39 
40 #ifndef _REENT_ONLY
41 
42 int
vdprintf(int fd,const char * __restrict format,va_list ap)43 vdprintf (int fd,
44        const char *__restrict format,
45        va_list ap)
46 {
47   return _vdprintf_r (_REENT, fd, format, ap);
48 }
49 
50 #ifdef _NANO_FORMATTED_IO
51 int
52 vdiprintf (int, const char *, __VALIST)
53        _ATTRIBUTE ((__alias__("vdprintf")));
54 #endif
55 #endif /* ! _REENT_ONLY */
56