scons --> make
[aftubes.git] / errors.c
blobb54bc8142292ca11dec8b7fdafa4bfdb9b1b90fe
1 #include "errors.h"
2 #include "stdarg.h"
3 #include "stdio.h"
5 static __thread struct {
6 err_t errno;
7 const char *file;
8 const char *func;
9 int line;
10 char *msg;
11 void *object;
12 } errinfo = {0, NULL, NULL, 0, NULL, NULL};
14 err_t make_error_internal(err_t n, void *obj, const char *file, const char *func, int line, const char *fmt, ...)
16 va_list ap;
17 va_start(ap, fmt);
18 vasprintf(&errinfo.msg, fmt, ap);
19 va_end(ap);
20 errinfo.errno = n;
21 errinfo.file = file;
22 errinfo.func = func;
23 errinfo.line = line;
24 errinfo.object = obj;
25 return n;
28 err_t get_last_error(void)
30 return errinfo.errno;
33 const char *get_last_error_file(void)
35 return errinfo.file;
38 const char *get_last_error_func(void)
40 return errinfo.func;
43 int get_last_error_line(void)
45 return errinfo.line;
48 const char *get_last_error_message(void)
50 return errinfo.msg;