26 |
|
#endif |
27 |
|
|
28 |
|
#include <stdlib.h> |
29 |
+ |
#include <string.h> |
30 |
+ |
#include <errno.h> |
31 |
|
|
32 |
|
#include "statgrab.h" |
33 |
+ |
#include "tools.h" |
34 |
|
|
35 |
|
static sg_error error = SG_ERROR_NONE; |
36 |
+ |
#define ERROR_ARG_MAX 256 |
37 |
+ |
static char error_arg[ERROR_ARG_MAX]; |
38 |
+ |
static int errno_value = 0; |
39 |
|
|
40 |
|
void sg_set_error(sg_error code, const char *arg) { |
41 |
|
error = code; |
42 |
< |
/* FIXME do something with arg */ |
42 |
> |
if (arg != NULL) { |
43 |
> |
sg_strlcpy(error_arg, arg, sizeof error_arg); |
44 |
> |
} |
45 |
> |
else { |
46 |
> |
/* FIXME is this the best idea? */ |
47 |
> |
error_arg[0] = '\0'; |
48 |
> |
} |
49 |
|
} |
50 |
|
|
51 |
+ |
void sg_set_error_with_errno(sg_error code, const char *arg) { |
52 |
+ |
errno_value = errno; |
53 |
+ |
sg_set_error(code, arg); |
54 |
+ |
} |
55 |
+ |
|
56 |
|
sg_error sg_get_error() { |
57 |
|
return error; |
58 |
|
} |
59 |
|
|
60 |
+ |
const char *sg_get_error_arg() { |
61 |
+ |
return error_arg; |
62 |
+ |
} |
63 |
+ |
|
64 |
+ |
const int sg_get_error_errno() { |
65 |
+ |
return errno_value; |
66 |
+ |
} |
67 |
+ |
|
68 |
|
const char *sg_str_error(sg_error code) { |
69 |
|
switch (code) { |
70 |
|
case SG_ERROR_NONE: |
127 |
|
return "unsupported function"; |
128 |
|
case SG_ERROR_XSW_VER_MISMATCH: |
129 |
|
return "XSW version mismatch"; |
105 |
– |
default: |
106 |
– |
return "unknown error"; |
130 |
|
} |
131 |
+ |
return "unknown error"; |
132 |
|
} |
133 |
|
|