summaryrefslogtreecommitdiff
path: root/usr.sbin/unbound/ldns/drill/error.c
blob: e67b7fca020a3f8fe14f55c73808b10f8f34e670 (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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/**
 * error.c
 *
 * error reporting routines
 * basicly wrappers around printf
 *
 * (c) 2005 NLnet Labs
 *
 * See the file LICENSE for the license
 *
 */

#include "drill.h"
#include <ldns/ldns.h>

static void
warning_va_list(const char *fmt, va_list args)
{
        fprintf(stderr, "Warning: ");
        vfprintf(stderr, fmt, args);
        fprintf(stderr, "\n");
}

void
warning(const char *fmt, ...)
{
	va_list args;
	va_start(args, fmt);
	warning_va_list(fmt, args);
	va_end(args);
}

static void
error_va_list(const char *fmt, va_list args)
{
        fprintf(stderr, "Error: ");
        vfprintf(stderr, fmt, args);
        fprintf(stderr, "\n");
}

void
error(const char *fmt, ...)
{
	va_list args;
	va_start(args, fmt);
	error_va_list(fmt, args);
	va_end(args);
	exit(EXIT_FAILURE);
}

static void
verbose_va_list(const char *fmt, va_list args)
{
        vfprintf(stdout, fmt, args);
        fprintf(stdout, "\n");
}

/* print stuff */
void
mesg(const char *fmt, ...)
{
	va_list args;
	if (verbosity == -1) {
		return;
	}
	fprintf(stdout, ";; ");
	va_start(args, fmt);
	verbose_va_list(fmt, args);
	va_end(args);
}

/* print stuff when in verbose mode (1) */
void
verbose(const char *fmt, ...)
{
	va_list args;
	if (verbosity < 1) {
		return;
	}

	va_start(args, fmt);
	verbose_va_list(fmt, args);
	va_end(args);
}

/* print stuff when in vverbose mode (2) */
void
vverbose(const char *fmt, ...)
{
	va_list args;
	if (verbosity < 2) {
		return;
	}

	va_start(args, fmt);
	verbose_va_list(fmt, args);
	va_end(args);
}

static void
debug_va_list(const char *fmt, va_list args)
{
        vfprintf(stderr, fmt, args);
        fprintf(stderr, "\n");
}

void
debug(const char *fmt, ...)
{
	va_list args;
	fprintf(stderr, "[DEBUG] ");
	va_start(args, fmt);
	debug_va_list(fmt, args);
	va_end(args);
}