aboutsummaryrefslogtreecommitdiff
path: root/utils.c
blob: 8d1d073a397582355da749a7e0ea7b17cedec98d (plain)
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
70
71
72
73
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <errno.h>
#include <fcntl.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>

#include "utils.h"

static void
info_va (const char *msg, va_list va)
{
  fprintf (stderr, "%s: ", progname);
  vfprintf (stderr, msg, va);
  fputs ("\n", stderr);
}

void
info (const char *msg, ...)
{
  va_list ap;

  va_start (ap, msg);
  info_va (msg, ap);
  va_end (ap);
}

static void
warning_va (const char *msg, va_list va)
{
  fprintf (stderr, "%s: WARNING: ", progname);
  vfprintf (stderr, msg, va);
  if (errno)
    fprintf (stderr, ": %s", strerror (errno));
  fputs ("\n", stderr);
}

void
warning (const char *msg, ...)
{
  va_list ap;

  va_start (ap, msg);
  warning_va (msg, ap);
  va_end (ap);
}

static void
fatal_va (const char *msg, va_list va)
{
  fprintf (stderr, "%s: FATAL: ", progname);
  vfprintf (stderr, msg, va);
  if (errno)
    fprintf (stderr, ": %s", strerror (errno));
  fputs ("\n", stderr);
}

void
fatal (const char *msg, ...)
{
  va_list ap;

  va_start (ap, msg);
  fatal_va (msg, ap);
  va_end (ap);
  exit (EXIT_FAILURE);
}