-
Notifications
You must be signed in to change notification settings - Fork 2
/
error.c
97 lines (84 loc) · 1.57 KB
/
error.c
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
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Copyright (C) 2009 John Kacur <jkacur@redhat.com>
*
* error routines, similar to those found in
* Advanced Programming in the UNIX Environment 2nd ed.
*/
#include "error.h"
/* Print an error message, plus a message for err and exit with error err */
void err_exit(int err, char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
err_doit(err, fmt, ap);
va_end(ap);
exit(err);
}
/* print an error message and return */
void err_msg(char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
err_doit(0, fmt, ap);
va_end(ap);
return;
}
/* Print an error message, plus a message for err, and return */
void err_msg_n(int err, char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
err_doit(err, fmt, ap);
va_end(ap);
return;
}
/* print an error message and quit */
void err_quit(char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
err_doit(0, fmt, ap);
va_end(ap);
exit(1);
}
void debug(char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
fputs("DEBUG: ", stderr);
err_doit(0, fmt, ap);
va_end(ap);
}
void info(char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
fputs("INFO: ", stderr);
err_doit(0, fmt, ap);
va_end(ap);
}
void warn(char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
fputs("WARN: ", stderr);
err_doit(0, fmt, ap);
va_end(ap);
}
void fatal(char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
fputs("FATAL: ", stderr);
err_doit(0, fmt, ap);
va_end(ap);
exit(EXIT_FAILURE);
}
void err_doit(int err, const char *fmt, va_list ap)
{
vfprintf(stderr, fmt, ap);
if (err)
fprintf(stderr, ": %s\n", strerror(err));
return;
}