Dropped char* error file to unify common error strings handling.
[akaros.git] / kern / include / err.h
1 /* Plan9 style error popping.  For details, read Documentation/plan9.txt */
2
3 #ifndef ROS_KERN_ERR_H
4 #define ROS_KERN_ERR_H
5
6 #include <setjmp.h>
7 #include <kthread.h>
8 #include <error.h>
9
10 #define ERRSTACK(x) struct errbuf *prev_errbuf; struct errbuf errstack[(x)];   \
11                     int curindex = 0;
12 #define waserror() (errpush(errstack, ARRAY_SIZE(errstack), &curindex,         \
13                             &prev_errbuf) ||                                   \
14                     setjmp(&(get_cur_errbuf()->jmpbuf)))
15 #define error(e, x, ...)                                                \
16         do {                                                                            \
17                 if (x != NULL)                                                                                                  \
18                         set_errstr(x, ##__VA_ARGS__);                                                           \
19                 else                                                                                                                    \
20                         set_errstr(errno_to_string(e));                                                         \
21                 set_errno(e);                                                                                                   \
22                 longjmp(&get_cur_errbuf()->jmpbuf, 1);                                                  \
23         } while(0)
24 #define nexterror() \
25         do {                                                                                                                            \
26                 errpop(errstack, ARRAY_SIZE(errstack), &curindex,                               \
27                            prev_errbuf);                                                                                        \
28                 longjmp(&(get_cur_errbuf())->jmpbuf, 1);                                                \
29         } while (0)
30 #define poperror() errpop(errstack, ARRAY_SIZE(errstack), &curindex,    \
31                                                   prev_errbuf)
32
33 int errpush(struct errbuf *errstack, int stacksize, int *curindex,
34             struct errbuf **prev_errbuf);
35 void errpop(struct errbuf *errstack, int stacksize, int *curindex,
36             struct errbuf *prev_errbuf);
37
38 #endif /* ROS_KERN_ERR_H */