-
Notifications
You must be signed in to change notification settings - Fork 1
/
err.c
62 lines (51 loc) · 999 Bytes
/
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
54
55
56
57
58
59
60
61
62
#include <stdarg.h>
#include <stdlib.h>
#include <stdio.h>
#include "inc/def.h"
#include "co/macro.h"
#include "co/err.h"
#define SIZE (MAX_STRING_SIZE)
enum { ERR_ABORT, ERR_IGNORE };
static int Type = ERR_ABORT;
void
he_err(__UNUSED int code, const char *file, int line, const char *fmt, ...)
{
char msg[SIZE];
va_list ap;
va_start(ap, fmt);
vsnprintf(msg, SIZE, fmt, ap);
va_end(ap);
fprintf(stderr, "%s:%d: %s\n", file, line, msg);
if (Type == ERR_ABORT)
abort();
else if (code == CO_USER)
exit(2);
}
void
he_msg(const char *file, int line, const char *fmt, ...)
{
char msg[SIZE];
va_list ap;
va_start(ap, fmt);
vsnprintf(msg, SIZE, fmt, ap);
va_end(ap);
fprintf(stderr, "%s:%d: %s\n", file, line, msg);
}
int
err_set(int new)
{
int old;
old = Type;
Type = new;
return old;
}
int
err_set_abort(void)
{
return err_set(ERR_ABORT);
}
int
err_set_ignore(void)
{
return err_set(ERR_IGNORE);
}