-
Notifications
You must be signed in to change notification settings - Fork 1
/
err.c
53 lines (45 loc) · 1.12 KB
/
err.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
/* err.c: Error handling and reporting.
*
* Copyright (C) 2001-2006 by Brian Raiter, under the GNU General Public
* License. No warranty. See COPYING for details.
*/
#include <stdlib.h>
#include <stdarg.h>
#include "oshw.h"
#include "err.h"
/* "Hidden" arguments to _warn, _errmsg, and _die.
*/
char const *_err_cfile = NULL;
unsigned long _err_lineno = 0;
/* Log a warning message.
*/
void _warn(char const *fmt, ...)
{
va_list args;
va_start(args, fmt);
usermessage(NOTIFY_LOG, NULL, _err_cfile, _err_lineno, fmt, args);
va_end(args);
_err_cfile = NULL;
_err_lineno = 0;
}
/* Display an error message to the user.
*/
void _errmsg(char const *prefix, char const *fmt, ...)
{
va_list args;
va_start(args, fmt);
usermessage(NOTIFY_ERR, prefix, _err_cfile, _err_lineno, fmt, args);
va_end(args);
_err_cfile = NULL;
_err_lineno = 0;
}
/* Display an error message to the user and exit.
*/
void _die(char const *fmt, ...)
{
va_list args;
va_start(args, fmt);
usermessage(NOTIFY_DIE, NULL, _err_cfile, _err_lineno, fmt, args);
va_end(args);
exit(EXIT_FAILURE);
}