Diffstat (limited to 'libical/src/libical/icalerror.c') (more/less context) (ignore whitespace changes)
-rw-r--r-- | libical/src/libical/icalerror.c | 54 |
1 files changed, 48 insertions, 6 deletions
diff --git a/libical/src/libical/icalerror.c b/libical/src/libical/icalerror.c index d44d37a..61043b2 100644 --- a/libical/src/libical/icalerror.c +++ b/libical/src/libical/icalerror.c | |||
@@ -26,19 +26,59 @@ | |||
26 | 26 | ||
27 | 27 | ||
28 | #ifdef HAVE_CONFIG_H | 28 | #ifdef HAVE_CONFIG_H |
29 | #include "config.h" | 29 | #include "config.h" |
30 | #endif | 30 | #endif |
31 | 31 | ||
32 | #include <stdlib.h> /* for malloc() */ | ||
33 | #include <string.h> /* for strcmp */ | ||
32 | #include "icalerror.h" | 34 | #include "icalerror.h" |
33 | 35 | ||
34 | #include <string.h> | 36 | #ifdef HAVE_PTHREAD |
37 | #include <pthread.h> | ||
35 | 38 | ||
36 | icalerrorenum icalerrno; | 39 | static pthread_key_t icalerrno_key; |
40 | static pthread_once_t icalerrno_key_once = PTHREAD_ONCE_INIT; | ||
41 | |||
42 | static void icalerrno_destroy(void* buf) { | ||
43 | free(buf); | ||
44 | pthread_setspecific(icalerrno_key, NULL); | ||
45 | } | ||
46 | |||
47 | static void icalerrno_key_alloc(void) { | ||
48 | pthread_key_create(&icalerrno_key, icalerrno_destroy); | ||
49 | } | ||
50 | |||
51 | icalerrorenum *icalerrno_return(void) { | ||
52 | icalerrorenum *_errno; | ||
53 | |||
54 | pthread_once(&icalerrno_key_once, icalerrno_key_alloc); | ||
55 | |||
56 | _errno = (icalerrorenum*) pthread_getspecific(icalerrno_key); | ||
57 | |||
58 | if (!_errno) { | ||
59 | _errno = malloc(sizeof(icalerrorenum)); | ||
60 | *_errno = ICAL_NO_ERROR; | ||
61 | pthread_setspecific(icalerrno_key, _errno); | ||
62 | } | ||
63 | return _errno; | ||
64 | } | ||
65 | |||
66 | #else | ||
67 | |||
68 | static icalerrorenum icalerrno_storage = ICAL_NO_ERROR; | ||
69 | |||
70 | icalerrorenum *icalerrno_return(void) { | ||
71 | return &icalerrno_storage; | ||
72 | } | ||
73 | |||
74 | #endif | ||
75 | |||
76 | |||
77 | static int foo; | ||
37 | 78 | ||
38 | int foo; | ||
39 | void icalerror_stop_here(void) | 79 | void icalerror_stop_here(void) |
40 | { | 80 | { |
41 | foo++; /* Keep optimizers from removing routine */ | 81 | foo++; /* Keep optimizers from removing routine */ |
42 | } | 82 | } |
43 | 83 | ||
44 | void icalerror_crash_here(void) | 84 | void icalerror_crash_here(void) |
@@ -76,16 +116,17 @@ int icalerror_errors_are_fatal = 0; | |||
76 | 116 | ||
77 | struct icalerror_state { | 117 | struct icalerror_state { |
78 | icalerrorenum error; | 118 | icalerrorenum error; |
79 | icalerrorstate state; | 119 | icalerrorstate state; |
80 | }; | 120 | }; |
81 | 121 | ||
82 | struct icalerror_state error_state_map[] = | 122 | static struct icalerror_state error_state_map[] = |
83 | { | 123 | { |
84 | { ICAL_BADARG_ERROR,ICAL_ERROR_DEFAULT}, | 124 | { ICAL_BADARG_ERROR,ICAL_ERROR_DEFAULT}, |
85 | { ICAL_NEWFAILED_ERROR,ICAL_ERROR_DEFAULT}, | 125 | { ICAL_NEWFAILED_ERROR,ICAL_ERROR_DEFAULT}, |
126 | { ICAL_ALLOCATION_ERROR,ICAL_ERROR_DEFAULT}, | ||
86 | { ICAL_MALFORMEDDATA_ERROR,ICAL_ERROR_DEFAULT}, | 127 | { ICAL_MALFORMEDDATA_ERROR,ICAL_ERROR_DEFAULT}, |
87 | { ICAL_PARSE_ERROR,ICAL_ERROR_DEFAULT}, | 128 | { ICAL_PARSE_ERROR,ICAL_ERROR_DEFAULT}, |
88 | { ICAL_INTERNAL_ERROR,ICAL_ERROR_DEFAULT}, | 129 | { ICAL_INTERNAL_ERROR,ICAL_ERROR_DEFAULT}, |
89 | { ICAL_FILE_ERROR,ICAL_ERROR_DEFAULT}, | 130 | { ICAL_FILE_ERROR,ICAL_ERROR_DEFAULT}, |
90 | { ICAL_USAGE_ERROR,ICAL_ERROR_DEFAULT}, | 131 | { ICAL_USAGE_ERROR,ICAL_ERROR_DEFAULT}, |
91 | { ICAL_UNIMPLEMENTED_ERROR,ICAL_ERROR_DEFAULT}, | 132 | { ICAL_UNIMPLEMENTED_ERROR,ICAL_ERROR_DEFAULT}, |
@@ -101,12 +142,13 @@ struct icalerror_string_map { | |||
101 | }; | 142 | }; |
102 | 143 | ||
103 | static struct icalerror_string_map string_map[] = | 144 | static struct icalerror_string_map string_map[] = |
104 | { | 145 | { |
105 | {"BADARG",ICAL_BADARG_ERROR,"BADARG: Bad argument to function"}, | 146 | {"BADARG",ICAL_BADARG_ERROR,"BADARG: Bad argument to function"}, |
106 | { "NEWFAILED",ICAL_NEWFAILED_ERROR,"NEWFAILED: Failed to create a new object via a *_new() routine"}, | 147 | { "NEWFAILED",ICAL_NEWFAILED_ERROR,"NEWFAILED: Failed to create a new object via a *_new() routine"}, |
148 | { "ALLOCATION",ICAL_ALLOCATION_ERROR,"ALLOCATION: Failed to allocate new memory"}, | ||
107 | {"MALFORMEDDATA",ICAL_MALFORMEDDATA_ERROR,"MALFORMEDDATA: An input string was not correctly formed or a component has missing or extra properties"}, | 149 | {"MALFORMEDDATA",ICAL_MALFORMEDDATA_ERROR,"MALFORMEDDATA: An input string was not correctly formed or a component has missing or extra properties"}, |
108 | { "PARSE",ICAL_PARSE_ERROR,"PARSE: Failed to parse a part of an iCal component"}, | 150 | { "PARSE",ICAL_PARSE_ERROR,"PARSE: Failed to parse a part of an iCal component"}, |
109 | {"INTERNAL",ICAL_INTERNAL_ERROR,"INTERNAL: Random internal error. This indicates an error in the library code, not an error in use"}, | 151 | {"INTERNAL",ICAL_INTERNAL_ERROR,"INTERNAL: Random internal error. This indicates an error in the library code, not an error in use"}, |
110 | { "FILE",ICAL_FILE_ERROR,"FILE: An operation on a file failed. Check errno for more detail."}, | 152 | { "FILE",ICAL_FILE_ERROR,"FILE: An operation on a file failed. Check errno for more detail."}, |
111 | { "USAGE",ICAL_USAGE_ERROR,"USAGE: Failed to propertyl sequence calls to a set of interfaces"}, | 153 | { "USAGE",ICAL_USAGE_ERROR,"USAGE: Failed to propertyl sequence calls to a set of interfaces"}, |
112 | { "UNIMPLEMENTED",ICAL_UNIMPLEMENTED_ERROR,"UNIMPLEMENTED: This feature has not been implemented"}, | 154 | { "UNIMPLEMENTED",ICAL_UNIMPLEMENTED_ERROR,"UNIMPLEMENTED: This feature has not been implemented"}, |
@@ -165,24 +207,24 @@ void icalerror_restore(const char* error, icalerrorstate es){ | |||
165 | 207 | ||
166 | void icalerror_set_error_state( icalerrorenum error, | 208 | void icalerror_set_error_state( icalerrorenum error, |
167 | icalerrorstate state) | 209 | icalerrorstate state) |
168 | { | 210 | { |
169 | int i; | 211 | int i; |
170 | 212 | ||
171 | for(i = ICAL_BADARG_ERROR; error_state_map[i].error!= ICAL_NO_ERROR;i++){ | 213 | for(i = 0; error_state_map[i].error!= ICAL_NO_ERROR;i++){ |
172 | if(error_state_map[i].error == error){ | 214 | if(error_state_map[i].error == error){ |
173 | error_state_map[i].state = state; | 215 | error_state_map[i].state = state; |
174 | } | 216 | } |
175 | } | 217 | } |
176 | } | 218 | } |
177 | 219 | ||
178 | icalerrorstate icalerror_get_error_state( icalerrorenum error) | 220 | icalerrorstate icalerror_get_error_state( icalerrorenum error) |
179 | { | 221 | { |
180 | int i; | 222 | int i; |
181 | 223 | ||
182 | for(i = ICAL_BADARG_ERROR; error_state_map[i].error!= ICAL_NO_ERROR;i++){ | 224 | for(i = 0; error_state_map[i].error!= ICAL_NO_ERROR;i++){ |
183 | if(error_state_map[i].error == error){ | 225 | if(error_state_map[i].error == error){ |
184 | return error_state_map[i].state; | 226 | return error_state_map[i].state; |
185 | } | 227 | } |
186 | } | 228 | } |
187 | 229 | ||
188 | return ICAL_ERROR_UNKNOWN; | 230 | return ICAL_ERROR_UNKNOWN; |