Line data Source code
1 : /* -*- buffer-read-only: t -*- vi: set ro: */
2 : /* DO NOT EDIT! GENERATED AUTOMATICALLY! */
3 : #line 1
4 : /* Formatted output to a stream.
5 : Copyright (C) 2004, 2006-2008 Free Software Foundation, Inc.
6 :
7 : This program is free software: you can redistribute it and/or modify
8 : it under the terms of the GNU General Public License as published by
9 : the Free Software Foundation; either version 3 of the License, or
10 : (at your option) any later version.
11 :
12 : This program is distributed in the hope that it will be useful,
13 : but WITHOUT ANY WARRANTY; without even the implied warranty of
14 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 : GNU General Public License for more details.
16 :
17 : You should have received a copy of the GNU General Public License
18 : along with this program. If not, see <http://www.gnu.org/licenses/>. */
19 :
20 : #if 1
21 : # include <config.h>
22 : #endif
23 :
24 : /* Specification. */
25 : #include <stdio.h>
26 :
27 : #include <errno.h>
28 : #include <limits.h>
29 : #include <stdarg.h>
30 : #include <stdlib.h>
31 :
32 : #include "fseterr.h"
33 : #include "vasnprintf.h"
34 :
35 : /* Print formatted output to the stream FP.
36 131 : Return string length of formatted string. On error, return a negative
37 : value. */
38 : int
39 : vfprintf (FILE *fp, const char *format, va_list args)
40 : {
41 131 : char buf[2000];
42 : char *output;
43 131 : size_t len;
44 131 : size_t lenbuf = sizeof (buf);
45 :
46 131 : output = vasnprintf (buf, &lenbuf, format, args);
47 : len = lenbuf;
48 0 :
49 0 : if (!output)
50 : {
51 : fseterr (fp);
52 131 : return -1;
53 : }
54 0 :
55 : if (fwrite (output, 1, len, fp) < len)
56 0 : {
57 0 : if (output != buf)
58 0 : {
59 : int saved_errno = errno;
60 0 : free (output);
61 : errno = saved_errno;
62 : }
63 131 : return -1;
64 : }
65 0 :
66 0 : if (len > INT_MAX)
67 0 : {
68 : errno = EOVERFLOW;
69 : fseterr (fp);
70 131 : return -1;
71 : }
72 :
73 : return len;
74 : }
|