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@civicknowledge.com>
6
7 This library is free software; you can redistribute it and/or modify
8 it under the terms of either:
9
10 The LGPL as published by the Free Software Foundation, version
11 2.1, available at: https://www.gnu.org/licenses/lgpl-2.1.html
12
13 Or:
14
15 The Mozilla Public License Version 2.0. You may obtain a copy of
16 the License at https://www.mozilla.org/MPL/
17
18 The original code is icalerror.h
19======================================================================*/
20
21#ifndef ICALERROR_H
22#define ICALERROR_H
23
24#include "libical_ical_export.h"
25#include <assert.h>
26#include <stdio.h>
27
40#define ICAL_SETERROR_ISFUNC
41
52LIBICAL_ICAL_EXPORT void icalerror_stop_here(void);
53
60LIBICAL_ICAL_EXPORT void icalerror_crash_here(void);
61
62#ifndef _MSC_VER
63#pragma GCC visibility push(default)
64#endif
75 typedef enum icalerrorenum
76{
78 ICAL_NO_ERROR = 0,
79
81 ICAL_BADARG_ERROR,
82
84 ICAL_NEWFAILED_ERROR,
85
87 ICAL_ALLOCATION_ERROR,
88
90 ICAL_MALFORMEDDATA_ERROR,
91
93 ICAL_PARSE_ERROR,
94
96 ICAL_INTERNAL_ERROR, /* Like assert --internal consist. prob */
97
99 ICAL_FILE_ERROR,
100
102 ICAL_USAGE_ERROR,
103
105 ICAL_UNIMPLEMENTED_ERROR,
106
108 ICAL_UNKNOWN_ERROR /* Used for problems in input to icalerror_strerror() */
109} icalerrorenum;
110#ifndef _MSC_VER
111#pragma GCC visibility pop
112#endif
113
126LIBICAL_ICAL_EXPORT icalerrorenum *icalerrno_return(void);
127
144#define icalerrno (*(icalerrno_return()))
145
158LIBICAL_ICAL_EXPORT void icalerror_set_errors_are_fatal(int fatal);
159
173LIBICAL_ICAL_EXPORT int icalerror_get_errors_are_fatal(void);
174
175/* Warning messages */
176
188#ifdef __GNUC__ca
189#define icalerror_warn(message) \
190{fprintf(stderr, "%s(), %s:%d: %s\n", __FUNCTION__, __FILE__, __LINE__, message);}
191#else /* __GNU_C__ */
192#define icalerror_warn(message) \
193{fprintf(stderr, "%s:%d: %s\n", __FILE__, __LINE__, message);}
194#endif /* __GNU_C__ */
195
207LIBICAL_ICAL_EXPORT void icalerror_clear_errno(void);
208
214 typedef enum icalerrorstate
215{
217 ICAL_ERROR_FATAL,
218
220 ICAL_ERROR_NONFATAL,
221
223 ICAL_ERROR_DEFAULT,
224
226 ICAL_ERROR_UNKNOWN
227} icalerrorstate;
228
249LIBICAL_ICAL_EXPORT const char *icalerror_strerror(icalerrorenum e);
250
269LIBICAL_ICAL_EXPORT const char *icalerror_perror(void);
270
282LIBICAL_ICAL_EXPORT void ical_bt(void);
283
297LIBICAL_ICAL_EXPORT void icalerror_set_error_state(icalerrorenum error, icalerrorstate state);
298
304LIBICAL_ICAL_EXPORT icalerrorstate icalerror_get_error_state(icalerrorenum error);
305
321LIBICAL_ICAL_EXPORT icalerrorenum icalerror_error_from_string(const char *str);
322
338#if !defined(ICAL_SETERROR_ISFUNC)
339#define icalerror_set_errno(x) \
340 icalerrno = x; \
341 if(icalerror_get_error_state(x) == ICAL_ERROR_FATAL || \
342 (icalerror_get_error_state(x) == ICAL_ERROR_DEFAULT && \
343 icalerror_get_errors_are_fatal() == 1)){ \
344 icalerror_warn(icalerror_strerror(x)); \
345 ical_bt(); \
346 assert(0); \
347} }
348#else
363LIBICAL_ICAL_EXPORT void icalerror_set_errno(icalerrorenum x);
364#endif
365
378#if !defined(ICAL_ERRORS_ARE_FATAL)
379#define ICAL_ERRORS_ARE_FATAL 0
380#endif
381
382#if ICAL_ERRORS_ARE_FATAL == 1
383#undef NDEBUG
384#endif
385
386#define icalerror_check_value_type(value,type);
387#define icalerror_check_property_type(value,type);
388#define icalerror_check_parameter_type(value,type);
389#define icalerror_check_component_type(value,type);
390
391/* Assert with a message */
403#if ICAL_ERRORS_ARE_FATAL == 1
404
405#ifdef __GNUC__
406#define icalerror_assert(test,message) \
407 if (!(test)) { \
408 fprintf(stderr, "%s(), %s:%d: %s\n", __FUNCTION__, __FILE__, __LINE__, message); \
409 icalerror_stop_here(); \
410 abort();}
411#else /*__GNUC__*/
412#define icalerror_assert(test,message) \
413 if (!(test)) { \
414 fprintf(stderr, "%s:%d: %s\n", __FILE__, __LINE__, message); \
415 icalerror_stop_here(); \
416 abort();}
417#endif /*__GNUC__*/
418
419#else /* ICAL_ERRORS_ARE_FATAL */
420#define icalerror_assert(test,message)
421#endif /* ICAL_ERRORS_ARE_FATAL */
422
441#define icalerror_check_arg(test,arg) \
442 if (!(test)) { \
443 icalerror_set_errno(ICAL_BADARG_ERROR); \
444}
445
465#define icalerror_check_arg_rv(test,arg) \
466 if (!(test)) { \
467 icalerror_set_errno(ICAL_BADARG_ERROR); \
468 return; \
469}
470
491#define icalerror_check_arg_rz(test,arg) \
492 if (!(test)) { \
493 icalerror_set_errno(ICAL_BADARG_ERROR); \
494 return 0; \
495}
496
518#define icalerror_check_arg_re(test,arg,error) \
519 if (!(test)) { \
520 icalerror_stop_here(); \
521 assert(0); \
522 return error; \
523}
524
546#define icalerror_check_arg_rx(test,arg,x) \
547 if (!(test)) { \
548 icalerror_set_errno(ICAL_BADARG_ERROR); \
549 return x; \
550}
551
552/* String interfaces to set an error to NONFATAL and restore it to its original value */
553
569LIBICAL_ICAL_EXPORT icalerrorstate icalerror_supress(const char *error);
570
589LIBICAL_ICAL_EXPORT void icalerror_restore(const char *error, icalerrorstate es);
590
591#endif /* !ICALERROR_H */
icalerrno_return
icalerrorenum * icalerrno_return(void)
Returns the current icalerrno value.
Definition: icalerror.c:70
icalerror_set_errors_are_fatal
void icalerror_set_errors_are_fatal(int fatal)
Change if errors are fatal.
Definition: icalerror.c:106
icalerror_crash_here
void icalerror_crash_here(void)
Triggered to abort the process.
Definition: icalerror.c:84
ical_bt
void ical_bt(void)
Prints backtrace.
Definition: icalerror.c:260
icalerrorstate
icalerrorstate
Determine if an error is fatal or non-fatal.
Definition: icalerror.h:215
ICAL_ERROR_UNKNOWN
@ ICAL_ERROR_UNKNOWN
Definition: icalerror.h:226
ICAL_ERROR_FATAL
@ ICAL_ERROR_FATAL
Definition: icalerror.h:217
ICAL_ERROR_DEFAULT
@ ICAL_ERROR_DEFAULT
Definition: icalerror.h:223
ICAL_ERROR_NONFATAL
@ ICAL_ERROR_NONFATAL
Definition: icalerror.h:220
icalerror_get_errors_are_fatal
int icalerror_get_errors_are_fatal(void)
Determine if errors are fatal.
Definition: icalerror.c:111
icalerror_perror
const char * icalerror_perror(void)
Returns the description string for the current error in icalerrno.
Definition: icalerror.c:209
icalerror_get_error_state
icalerrorstate icalerror_get_error_state(icalerrorenum error)
Gets the error state (severity) for a given error.
Definition: icalerror.c:234
icalerrorenum
icalerrorenum
Represents the different types of errors that can be triggered in libical.
Definition: icalerror.h:76
ICAL_NEWFAILED_ERROR
@ ICAL_NEWFAILED_ERROR
Definition: icalerror.h:84
ICAL_BADARG_ERROR
@ ICAL_BADARG_ERROR
Definition: icalerror.h:81
ICAL_FILE_ERROR
@ ICAL_FILE_ERROR
Definition: icalerror.h:99
ICAL_ALLOCATION_ERROR
@ ICAL_ALLOCATION_ERROR
Definition: icalerror.h:87
ICAL_INTERNAL_ERROR
@ ICAL_INTERNAL_ERROR
Definition: icalerror.h:96
ICAL_NO_ERROR
@ ICAL_NO_ERROR
Definition: icalerror.h:78
ICAL_MALFORMEDDATA_ERROR
@ ICAL_MALFORMEDDATA_ERROR
Definition: icalerror.h:90
ICAL_UNKNOWN_ERROR
@ ICAL_UNKNOWN_ERROR
Definition: icalerror.h:108
ICAL_PARSE_ERROR
@ ICAL_PARSE_ERROR
Definition: icalerror.h:93
ICAL_UNIMPLEMENTED_ERROR
@ ICAL_UNIMPLEMENTED_ERROR
Definition: icalerror.h:105
ICAL_USAGE_ERROR
@ ICAL_USAGE_ERROR
Definition: icalerror.h:102
icalerror_set_error_state
void icalerror_set_error_state(icalerrorenum error, icalerrorstate state)
Sets the icalerrorstate for a given icalerrorenum error.
Definition: icalerror.c:223
icalerror_strerror
const char * icalerror_strerror(icalerrorenum e)
Finds the description string for error.
Definition: icalerror.c:247
icalerror_set_errno
void icalerror_set_errno(icalerrorenum x)
Sets the icalerrno to a given error.
Definition: icalerror.c:117
icalerror_restore
void icalerror_restore(const char *error, icalerrorstate es)
Definition: icalerror.c:214
icalerror_stop_here
void icalerror_stop_here(void)
Triggered before any error is called.
Definition: icalerror.c:79
icalerror_error_from_string
icalerrorenum icalerror_error_from_string(const char *str)
Reads an error from a string.
Definition: icalerror.c:181
icalerror_clear_errno
void icalerror_clear_errno(void)
Resets icalerrno to ICAL_NO_ERROR.
Definition: icalerror.c:95
icalerror_supress
icalerrorstate icalerror_supress(const char *error)
Suppresses a given error.
Definition: icalerror.c:194