-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathdtree_error.c
66 lines (52 loc) · 950 Bytes
/
dtree_error.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
63
64
65
#include "dtree.h"
#include "dtree_error.h"
#include <errno.h>
#include <string.h>
#include <assert.h>
/**
* Error state.
*/
static int error = 0;
/**
* Holds errno. It is valid when error
* is less then zero.
*/
static int xerrno = 0;
#define ERRSTR_COUNT ((int) (sizeof(errstr)/sizeof(char *)))
static const char *errstr[] = {
[0] = "Successful",
[DTREE_ECANT_READ_ROOT] = "Can not read the root dir"
};
void dtree_error_clear(void)
{
error = 0;
xerrno = 0;
}
void dtree_error_set(int e)
{
assert(e != 0);
error = e;
xerrno = errno;
}
void dtree_errno_set(int e)
{
error = -1;
xerrno = e;
}
void dtree_error_from_errno(void)
{
if(errno != 0)
dtree_errno_set(errno);
}
int dtree_iserror(void)
{
return error != 0;
}
const char *dtree_errstr(void)
{
if(error >= 0 && error < ERRSTR_COUNT)
return errstr[error];
if(error < 0)
return strerror(xerrno);
return "Unknown error occured";
}