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 <reent.h> |
---|
9 | #include <stdio.h> |
---|
10 | #include <stdlib.h> |
---|
11 | #include <unistd.h> |
---|
12 | #include <stdarg.h> |
---|
13 | #include "local.h" |
---|
14 | |
---|
15 | int |
---|
16 | _vdprintf_r (struct _reent *ptr, |
---|
17 | int fd, |
---|
18 | const char *__restrict 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 = _vasnprintf_r (ptr, buf, &n, format, ap); |
---|
27 | if (!p) |
---|
28 | return -1; |
---|
29 | n = _write_r (ptr, fd, p, n); |
---|
30 | if (p != buf) |
---|
31 | _free_r (ptr, p); |
---|
32 | return n; |
---|
33 | } |
---|
34 | |
---|
35 | #ifdef _NANO_FORMATTED_IO |
---|
36 | int |
---|
37 | _vdiprintf_r (struct _reent *, int, const char *, __VALIST) |
---|
38 | _ATTRIBUTE ((__alias__("_vdprintf_r"))); |
---|
39 | #endif |
---|
40 | |
---|
41 | #ifndef _REENT_ONLY |
---|
42 | |
---|
43 | int |
---|
44 | vdprintf (int fd, |
---|
45 | const char *__restrict format, |
---|
46 | va_list ap) |
---|
47 | { |
---|
48 | return _vdprintf_r (_REENT, fd, format, ap); |
---|
49 | } |
---|
50 | |
---|
51 | #ifdef _NANO_FORMATTED_IO |
---|
52 | int |
---|
53 | vdiprintf (int, const char *, __VALIST) |
---|
54 | _ATTRIBUTE ((__alias__("vdprintf"))); |
---|
55 | #endif |
---|
56 | #endif /* ! _REENT_ONLY */ |
---|