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 | |||
@@ -31,9 +31,49 @@ | |||
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) |
@@ -81,3 +121,3 @@ struct icalerror_state { | |||
81 | 121 | ||
82 | struct icalerror_state error_state_map[] = | 122 | static struct icalerror_state error_state_map[] = |
83 | { | 123 | { |
@@ -85,2 +125,3 @@ struct icalerror_state error_state_map[] = | |||
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}, |
@@ -106,2 +147,3 @@ static struct icalerror_string_map string_map[] = | |||
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"}, |
@@ -170,3 +212,3 @@ void icalerror_set_error_state( icalerrorenum error, | |||
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){ |
@@ -181,3 +223,3 @@ icalerrorstate icalerror_get_error_state( icalerrorenum error) | |||
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){ |