Libical API Documentation  3.0
icalerror.h
Go to the documentation of this file.
1 /*======================================================================
2  FILE: icalerror.h
3  CREATOR: eric 09 May 1999
4 
5  (C) COPYRIGHT 2000, Eric Busboom <eric@softwarestudio.org>
6  http://www.softwarestudio.org
7 
8  This library is free software; you can redistribute it and/or modify
9  it under the terms of either:
10 
11  The LGPL as published by the Free Software Foundation, version
12  2.1, available at: http://www.gnu.org/licenses/lgpl-2.1.html
13 
14  Or:
15 
16  The Mozilla Public License Version 2.0. You may obtain a copy of
17  the License at http://www.mozilla.org/MPL/
18 
19  The original code is icalerror.h
20 ======================================================================*/
21 
22 #ifndef ICALERROR_H
23 #define ICALERROR_H
24 
25 #include "libical_ical_export.h"
26 #include <assert.h>
27 #include <stdio.h>
28 
41 #define ICAL_SETERROR_ISFUNC
42 
53 LIBICAL_ICAL_EXPORT void icalerror_stop_here(void);
54 
61 LIBICAL_ICAL_EXPORT void icalerror_crash_here(void);
62 
63 #pragma GCC visibility push(default)
64 
74 typedef enum icalerrorenum
75 {
78 
81 
84 
87 
90 
93 
95  ICAL_INTERNAL_ERROR, /* Like assert --internal consist. prob */
96 
99 
102 
105 
107  ICAL_UNKNOWN_ERROR /* Used for problems in input to icalerror_strerror() */
108 } icalerrorenum;
109 #pragma GCC visibility pop
110 
123 LIBICAL_ICAL_EXPORT icalerrorenum *icalerrno_return(void);
124 
141 #define icalerrno (*(icalerrno_return()))
142 
155 LIBICAL_ICAL_EXPORT void icalerror_set_errors_are_fatal(int fatal);
156 
170 LIBICAL_ICAL_EXPORT int icalerror_get_errors_are_fatal(void);
171 
172 /* Warning messages */
173 
185 #ifdef __GNUC__ca
186 #define icalerror_warn(message) \
187 {fprintf(stderr, "%s(), %s:%d: %s\n", __FUNCTION__, __FILE__, __LINE__, message);}
188 #else /* __GNU_C__ */
189 #define icalerror_warn(message) \
190 {fprintf(stderr, "%s:%d: %s\n", __FILE__, __LINE__, message);}
191 #endif /* __GNU_C__ */
192 
204 LIBICAL_ICAL_EXPORT void icalerror_clear_errno(void);
205 
211 typedef enum icalerrorstate
212 {
215 
218 
221 
225 
246 LIBICAL_ICAL_EXPORT const char *icalerror_strerror(icalerrorenum e);
247 
266 LIBICAL_ICAL_EXPORT const char *icalerror_perror(void);
267 
279 LIBICAL_ICAL_EXPORT void ical_bt(void);
280 
294 LIBICAL_ICAL_EXPORT void icalerror_set_error_state(icalerrorenum error, icalerrorstate state);
295 
301 LIBICAL_ICAL_EXPORT icalerrorstate icalerror_get_error_state(icalerrorenum error);
302 
318 LIBICAL_ICAL_EXPORT icalerrorenum icalerror_error_from_string(const char *str);
319 
335 #if !defined(ICAL_SETERROR_ISFUNC)
336 #define icalerror_set_errno(x) \
337 icalerrno = x; \
338 if(icalerror_get_error_state(x) == ICAL_ERROR_FATAL || \
339  (icalerror_get_error_state(x) == ICAL_ERROR_DEFAULT && \
340  icalerror_get_errors_are_fatal() == 1)){ \
341  icalerror_warn(icalerror_strerror(x)); \
342  ical_bt(); \
343  assert(0); \
344 } }
345 #else
346 
360 LIBICAL_ICAL_EXPORT void icalerror_set_errno(icalerrorenum x);
361 #endif
362 
375 #if !defined(ICAL_ERRORS_ARE_FATAL)
376 #define ICAL_ERRORS_ARE_FATAL 0
377 #endif
378 
379 #if ICAL_ERRORS_ARE_FATAL == 1
380 #undef NDEBUG
381 #endif
382 
383 #define icalerror_check_value_type(value,type);
384 #define icalerror_check_property_type(value,type);
385 #define icalerror_check_parameter_type(value,type);
386 #define icalerror_check_component_type(value,type);
387 
388 /* Assert with a message */
400 #if ICAL_ERRORS_ARE_FATAL == 1
401 
402 #ifdef __GNUC__
403 #define icalerror_assert(test,message) \
404 if (!(test)) { \
405  fprintf(stderr, "%s(), %s:%d: %s\n", __FUNCTION__, __FILE__, __LINE__, message); \
406  icalerror_stop_here(); \
407  abort();}
408 #else /*__GNUC__*/
409 #define icalerror_assert(test,message) \
410 if (!(test)) { \
411  fprintf(stderr, "%s:%d: %s\n", __FILE__, __LINE__, message); \
412  icalerror_stop_here(); \
413  abort();}
414 #endif /*__GNUC__*/
415 
416 #else /* ICAL_ERRORS_ARE_FATAL */
417 #define icalerror_assert(test,message)
418 #endif /* ICAL_ERRORS_ARE_FATAL */
419 
438 #define icalerror_check_arg(test,arg) \
439 if (!(test)) { \
440  icalerror_set_errno(ICAL_BADARG_ERROR); \
441 }
442 
462 #define icalerror_check_arg_rv(test,arg) \
463 if (!(test)) { \
464  icalerror_set_errno(ICAL_BADARG_ERROR); \
465  return; \
466 }
467 
488 #define icalerror_check_arg_rz(test,arg) \
489 if (!(test)) { \
490  icalerror_set_errno(ICAL_BADARG_ERROR); \
491  return 0; \
492 }
493 
515 #define icalerror_check_arg_re(test,arg,error) \
516 if (!(test)) { \
517  icalerror_stop_here(); \
518  assert(0); \
519  return error; \
520 }
521 
543 #define icalerror_check_arg_rx(test,arg,x) \
544 if (!(test)) { \
545  icalerror_set_errno(ICAL_BADARG_ERROR); \
546  return x; \
547 }
548 
549 /* String interfaces to set an error to NONFATAL and restore it to its original value */
550 
566 LIBICAL_ICAL_EXPORT icalerrorstate icalerror_supress(const char *error);
567 
586 LIBICAL_ICAL_EXPORT void icalerror_restore(const char *error, icalerrorstate es);
587 
588 #endif /* !ICALERROR_H */
void icalerror_set_errors_are_fatal(int fatal)
Change if errors are fatal.
Definition: icalerror.c:107
const char * icalerror_strerror(icalerrorenum e)
Find description string for error.
Definition: icalerror.c:248
Definition: icalerror.h:86
Definition: icalerror.h:95
Definition: icalerror.h:101
void icalerror_set_errno(icalerrorenum x)
Sets the icalerrno to a given error.
Definition: icalerror.c:118
Definition: icalerror.h:107
Definition: icalerror.h:223
Definition: icalerror.h:80
icalerrorstate
Determine if an error is fatal or non-fatal.
Definition: icalerror.h:211
icalerrorenum
Represents the different types of errors that can be triggered in libical.
Definition: icalerror.h:74
icalerrorstate icalerror_get_error_state(icalerrorenum error)
Get the error state (severity) for a given error.
Definition: icalerror.c:235
void icalerror_stop_here(void)
Triggered before any error is called.
Definition: icalerror.c:80
int icalerror_get_errors_are_fatal(void)
Determine if errors are fatal.
Definition: icalerror.c:112
Definition: icalerror.h:92
Definition: icalerror.h:89
Definition: icalerror.h:214
Definition: icalerror.h:104
Definition: icalerror.h:83
icalerrorenum icalerror_error_from_string(const char *str)
Read an error from a string.
Definition: icalerror.c:182
Definition: icalerror.h:217
icalerrorenum * icalerrno_return(void)
Return the current icalerrno value.
Definition: icalerror.c:71
Definition: icalerror.h:98
icalerrorstate icalerror_supress(const char *error)
Suppresses a given error.
Definition: icalerror.c:195
void icalerror_crash_here(void)
Triggered to abort the process.
Definition: icalerror.c:85
void icalerror_set_error_state(icalerrorenum error, icalerrorstate state)
Set the icalerrorstate for a given icalerrorenum error.
Definition: icalerror.c:224
void icalerror_clear_errno(void)
Reset icalerrno to ICAL_NO_ERROR.
Definition: icalerror.c:96
const char * icalerror_perror(void)
Return the description string for the current error in icalerrno.
Definition: icalerror.c:210
Definition: icalerror.h:77
void icalerror_restore(const char *error, icalerrorstate es)
Definition: icalerror.c:215
Definition: icalerror.h:220
void ical_bt(void)
Prints backtrace.
Definition: icalerror.c:261