2 /*======================================================================
4 CREATOR: eric 09 May 1999
6 $Id: icalerror.h,v 1.17 2008-01-15 23:17:40 dothebart Exp $
9 (C) COPYRIGHT 2000, Eric Busboom <eric@softwarestudio.org>
10 http://www.softwarestudio.org
12 This program is free software; you can redistribute it and/or modify
13 it under the terms of either:
15 The LGPL as published by the Free Software Foundation, version
16 2.1, available at: http://www.fsf.org/copyleft/lesser.html
20 The Mozilla Public License Version 1.0. You may obtain a copy of
21 the License at http://www.mozilla.org/MPL/
23 The original code is icalerror.h
25 ======================================================================*/
32 #include <stdio.h> /* For icalerror_warn() */
39 #define ICAL_SETERROR_ISFUNC
42 /** This routine is called before any error is triggered. It is called
43 by icalerror_set_errno, so it does not appear in all of the macros
45 void icalerror_stop_here(void);
47 void icalerror_crash_here(void);
49 typedef enum icalerrorenum {
50 ICAL_NO_ERROR, /* icalerrno may not be initialized - put it first so and pray that the compiler initialize things to zero */
53 ICAL_ALLOCATION_ERROR,
54 ICAL_MALFORMEDDATA_ERROR,
56 ICAL_INTERNAL_ERROR, /* Like assert --internal consist. prob */
59 ICAL_UNIMPLEMENTED_ERROR,
60 ICAL_UNKNOWN_ERROR /* Used for problems in input to icalerror_strerror()*/
64 icalerrorenum * icalerrno_return(void);
65 #define icalerrno (*(icalerrno_return()))
67 /*#cmakedefine LIBICAL_STATIC 1*/
69 /** If true, libicl aborts after a call to icalerror_set_error
71 * @warning NOT THREAD SAFE -- recommended that you do not change
72 * this in a multithreaded program.
75 #if defined(LIBICAL_STATIC)
76 #define LIBICAL_EXPORT extern
77 #elif defined(BUILD_LIBICALDLL)
78 #define LIBICAL_EXPORT __declspec(dllexport)
80 #define LIBICAL_EXPORT __declspec(dllimport)
83 #define LIBICAL_EXPORT extern
86 LIBICAL_EXPORT int icalerror_errors_are_fatal;
88 /* Warning messages */
91 #define icalerror_warn(message) {fprintf(stderr,"%s(), %s:%d: %s\n",__FUNCTION__,__FILE__,__LINE__,message);}
93 #define icalerror_warn(message) {fprintf(stderr,"%s:%d: %s\n",__FILE__,__LINE__,message);}
94 #endif /* __GNU_C__ */
97 void icalerror_clear_errno(void);
98 void _icalerror_set_errno(icalerrorenum);
100 /* Make an individual error fatal or non-fatal. */
101 typedef enum icalerrorstate {
102 ICAL_ERROR_FATAL, /* Not fata */
103 ICAL_ERROR_NONFATAL, /* Fatal */
104 ICAL_ERROR_DEFAULT, /* Use the value of icalerror_errors_are_fatal*/
105 ICAL_ERROR_UNKNOWN /* Asked state for an unknown error type */
108 const char* icalerror_strerror(icalerrorenum e);
109 const char* icalerror_perror(void);
111 void icalerror_set_error_state( icalerrorenum error, icalerrorstate);
112 icalerrorstate icalerror_get_error_state( icalerrorenum error);
114 #ifndef ICAL_SETERROR_ISFUNC
115 #define icalerror_set_errno(x) \
117 if(icalerror_get_error_state(x)==ICAL_ERROR_FATAL || \
118 (icalerror_get_error_state(x)==ICAL_ERROR_DEFAULT && \
119 icalerror_errors_are_fatal == 1 )){ \
120 icalerror_warn(icalerror_strerror(x)); \
125 void icalerror_set_errno(icalerrorenum x);
128 #if !defined(ICAL_ERRORS_ARE_FATAL)
129 #define ICAL_ERRORS_ARE_FATAL 0
132 #if ICAL_ERRORS_ARE_FATAL == 1
136 #define icalerror_check_value_type(value,type);
137 #define icalerror_check_property_type(value,type);
138 #define icalerror_check_parameter_type(value,type);
139 #define icalerror_check_component_type(value,type);
141 /* Assert with a message */
142 #if ICAL_ERRORS_ARE_FATAL == 1
145 #define icalerror_assert(test,message) if(!(test)){fprintf(stderr,"%s(), %s:%d: %s\n",__FUNCTION__,__FILE__,__LINE__,message);icalerror_stop_here(); abort();}
147 #define icalerror_assert(test,message) if(!(test)){fprintf(stderr,"%s:%d: %s\n",__FILE__,__LINE__,message);icalerror_stop_here(); abort();}
150 #else /* ICAL_ERRORS_ARE_FATAL */
151 #define icalerror_assert(test,message)
152 #endif /* ICAL_ERRORS_ARE_FATAL */
154 /* Check & abort if check fails */
155 #define icalerror_check_arg(test,arg) if(!(test)) { icalerror_set_errno(ICAL_BADARG_ERROR); }
157 /* Check & return void if check fails*/
158 #define icalerror_check_arg_rv(test,arg) if(!(test)) {icalerror_set_errno(ICAL_BADARG_ERROR); return; }
160 /* Check & return 0 if check fails*/
161 #define icalerror_check_arg_rz(test,arg) if(!(test)) { icalerror_set_errno(ICAL_BADARG_ERROR); return 0;}
163 /* Check & return an error if check fails*/
164 #define icalerror_check_arg_re(test,arg,error) if(!(test)) { icalerror_stop_here(); assert(0); return error;}
166 /* Check & return something*/
167 #define icalerror_check_arg_rx(test,arg,x) if(!(test)) { icalerror_set_errno(ICAL_BADARG_ERROR); return x;}
171 /* String interfaces to set an error to NONFATAL and restore it to its
174 icalerrorstate icalerror_supress(const char* error);
175 void icalerror_restore(const char* error, icalerrorstate es);
178 #endif /* !ICALERROR_H */