-
Notifications
You must be signed in to change notification settings - Fork 0
/
err.cpp
41 lines (31 loc) · 798 Bytes
/
err.cpp
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
#include "assert.h"
#include "err.h"
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
static jmp_buf s_jump_buffers[32];
static int s_jsp = 0;
char g_err[4096];
// need stack of error messages (string)
//but what i did was i made error() and verify() actually take an enum value that was the error code and i returned that in the longjmp()
// then i had a matching const char* errmsg[] array that had formats for those
jmp_buf * push_handler_stack()
{
return &s_jump_buffers[s_jsp++];
}
void pop_handler_stack()
{
s_jsp--;
assert(s_jsp >= 0);
}
void verify(int cond, const char *format, ...)
{
if (cond == false) {
va_list argp;
va_start(argp, format);
vsprintf(g_err, format, argp);
va_end(argp);
assert(s_jsp > 0);
longjmp(s_jump_buffers[s_jsp - 1], -1);
}
}