xfprintf.c 1.01 KB
Newer Older
Christian Schäfer's avatar
Christian Schäfer committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/* Xfprintf --- extended formatted output to files.
   Copyright (C) 1995, 1996 Christian von Roques */

#ifdef HAVE_CONFIG_H
# include <config.h>
#endif

#ifndef USE_PRINTF

#include <assert.h>
#include "xprintf.h"


static int
xfprinter (void *f, const char *data, size_t len)
{
  size_t togo = len;

  while (togo > 0) {
    size_t n = fwrite (data, 1, togo, (FILE*)f);

    if (!n) return -1;
    togo -= n;
    data += n;
  }

  return len;
}


int
xfprintf (FILE *F, const char *fmt, ...)
{
  va_list args;
  int res;

  va_start (args, fmt);
  res = xvgprintf (xfprinter, F, fmt, args);
  va_end (args);
  return res;
}


int
xvfprintf (FILE *F, const char *fmt, va_list args)
{
  return xvgprintf (xfprinter, F, fmt, args);
}


int
xprintf (const char *fmt, ...)
{
  va_list args;
  int res;

  va_start (args, fmt);
  res = xvgprintf (xfprinter, stdout, fmt, args);
  va_end (args);
  return res;
}

int
xvprintf (const char *fmt, va_list args)
{
  return xvgprintf (xfprinter, stdout, fmt, args);
}

#endif /* USE_PRINTF */