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 | |||
@@ -29,13 +29,53 @@ | |||
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 */ |
@@ -79,10 +119,11 @@ struct icalerror_state { | |||
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}, |
@@ -104,6 +145,7 @@ 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"}, |
@@ -168,7 +210,7 @@ void icalerror_set_error_state( icalerrorenum error, | |||
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 | } |
@@ -179,7 +221,7 @@ 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 | } |