forked from TheGLander/tworld
-
Notifications
You must be signed in to change notification settings - Fork 0
/
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);
}