-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwa_result.c
More file actions
41 lines (36 loc) · 790 Bytes
/
Copy pathwa_result.c
File metadata and controls
41 lines (36 loc) · 790 Bytes
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
#include "wa_result.h"
#include <stdlib.h>
#include <string.h>
result_t res_new_ok(void) {
result_t x;
x.status = S_OK;
x.msg = 0;
return x;
}
result_t res_new_err(char* msg) {
result_t x;
x.status = S_ERR;
x.msg = msg;
return x;
}
result_t res_new_nest(result_t parent, char* msg) {
result_t x;
x.status = S_ERR_NEST;
x.msg = msg;
x.parent = res_clone(&parent);
return x;
}
bool res_ok(result_t r) {
return r.status == S_OK;
}
bool res_err(result_t r) {
return r.status == S_ERR || r.status == S_ERR_NEST;
}
const char* res_err_msg(result_t r) {
return r.msg;
}
result_t* res_clone(result_t* res) {
result_t* nres = (result_t*)calloc(1, sizeof(result_t));
memcpy(nres, res, sizeof(result_t));
return nres;
}