Added copyright headers
[libfirm] / ir / common / xfprintf.c
1 /*
2  * Project:     libFIRM
3  * File name:   ir/common/xfprintf.c
4  * Purpose:     Xfprintf --- extended formatted output to files.
5  * Author:      Christian von Roques
6  * Modified by:
7  * Created:     1999 by getting from fiasco
8  * CVS-ID:      $Id$
9  * Copyright:   (c) 1995, 1996 Christian von Roques
10  * Licence:     This file protected by GPL -  GNU GENERAL PUBLIC LICENSE.
11  */
12
13
14 #ifdef HAVE_CONFIG_H
15 # include <config.h>
16 #endif
17
18 #ifndef USE_PRINTF
19
20 #include <assert.h>
21 #include "xprintf.h"
22
23
24 static int
25 xfprinter (void *f, const char *data, size_t len)
26 {
27   size_t togo = len;
28
29   while (togo > 0) {
30     size_t n = fwrite (data, 1, togo, (FILE*)f);
31
32     if (!n) return -1;
33     togo -= n;
34     data += n;
35   }
36
37   return len;
38 }
39
40 int
41 xfprintf (FILE *F, const char *fmt, ...)
42 {
43   va_list args;
44   int res;
45
46   va_start (args, fmt);
47   res = xvgprintf (xfprinter, F, fmt, args);
48   va_end (args);
49   return res;
50 }
51
52
53 int
54 xvfprintf (FILE *F, const char *fmt, va_list args)
55 {
56   return xvgprintf (xfprinter, F, fmt, args);
57 }
58
59
60 int
61 xprintf (const char *fmt, ...)
62 {
63   va_list args;
64   int res;
65
66   va_start (args, fmt);
67   res = xvgprintf (xfprinter, stdout, fmt, args);
68   va_end (args);
69   return res;
70 }
71
72 int
73 xvprintf (const char *fmt, va_list args)
74 {
75   return xvgprintf (xfprinter, stdout, fmt, args);
76 }
77
78 #endif /* USE_PRINTF */