Libical API Documentation 4.0 UNRELEASED Go to the stable 3.0 documentation
Loading...
Searching...
No Matches
icalerror.c
Go to the documentation of this file.
1/*======================================================================
2 FILE: icalerror.c
3 CREATOR: eric 16 May 1999
4
5 SPDX-FileCopyrightText: 2000, Eric Busboom <eric@civicknowledge.com>
6 SPDX-License-Identifier: LGPL-2.1-only OR MPL-2.0
7======================================================================*/
8
13
14#ifdef HAVE_CONFIG_H
15#include <config.h>
16#endif
17
18#include "icalerror.h"
19#include "icalerror_p.h"
20#include "icalmemory.h"
21
22#include <stdbool.h>
23#include <stdlib.h>
24
25#if defined(HAVE_BACKTRACE)
26#include <execinfo.h>
27#endif
28
29static ICAL_GLOBAL_VAR bool icalerror_errors_are_fatal = false;
30
32{
33 icalerror_errors_are_fatal = fatal;
34}
35
37{
38 return icalerror_errors_are_fatal;
39}
40
41#if ICAL_SYNC_MODE == ICAL_SYNC_MODE_PTHREAD
42#include <pthread.h>
43
44static pthread_key_t icalerrno_key;
45static pthread_once_t icalerrno_key_once = PTHREAD_ONCE_INIT;
46
47static void icalerrno_destroy(void *buf)
48{
50 pthread_setspecific(icalerrno_key, NULL);
51}
52
53static void icalerrno_key_alloc(void)
54{
55 pthread_key_create(&icalerrno_key, icalerrno_destroy);
56}
57
59{
60 icalerrorenum *_errno;
61
62 pthread_once(&icalerrno_key_once, icalerrno_key_alloc);
63
64 _errno = (icalerrorenum *)pthread_getspecific(icalerrno_key);
65
66 if (!_errno) {
67 _errno = icalmemory_new_buffer(sizeof(icalerrorenum));
68 *_errno = ICAL_NO_ERROR;
69 pthread_setspecific(icalerrno_key, _errno);
70 }
71 return _errno;
72}
73
74#else
75
76static ICAL_GLOBAL_VAR icalerrorenum icalerrno_storage = ICAL_NO_ERROR;
77
79{
80 return &icalerrno_storage;
81}
82
83#endif
84
89
91{
92 icalerrno = x;
94 (icalerror_get_error_state(x) == ICAL_ERROR_DEFAULT && icalerror_errors_are_fatal == 1)) {
95 icalerror_warn(icalerror_strerror(x));
97 icalassert(0);
98 }
99}
100
102{
103#if defined(HAVE_BACKTRACE)
104 void *stack_frames[50];
105 int i, num;
106 size_t size;
107 char **strings;
108
109 size = sizeof(stack_frames) / sizeof(stack_frames[0]);
110 num = backtrace(stack_frames, (int)size);
111 strings = backtrace_symbols(stack_frames, num);
112 for (i = 0; i < num; i++) {
113 if (strings != NULL) {
114 icalerrprintf("%s\n", strings[i]);
115 } else {
116 icalerrprintf("%p\n", stack_frames[i]);
117 }
118 }
119 free((void *)strings); /* Not icalmemory_free_buffer(), allocated by backtrace_symbols() */
120#endif
121}
void icalerror_set_errors_are_fatal(bool fatal)
Change if errors are fatal.
Definition icalerror.c:31
icalerrorenum * icalerror_icalerrno(void)
Returns the current icalerrno value.
Definition icalerror.c:58
bool icalerror_get_errors_are_fatal(void)
Determine if errors are fatal.
Definition icalerror.c:36
void icalerror_backtrace(void)
Prints backtrace.
Definition icalerror.c:101
void icalerror_set_errno(icalerrorenum x)
Sets the icalerrno to a given error.
Definition icalerror.c:90
void icalerror_clear_errno(void)
Resets icalerrno to ICAL_NO_ERROR.
Definition icalerror.c:85
Error handling for libical.
@ ICAL_ERROR_FATAL
Definition icalerror.h:88
@ ICAL_ERROR_DEFAULT
Definition icalerror.h:94
icalerrorstate icalerror_get_error_state(icalerrorenum error)
Gets the error state (severity) for a given error.
icalerrorenum
Represents the different types of errors that can be triggered in libical.
Definition icalerror.h:42
@ ICAL_NO_ERROR
Definition icalerror.h:44
const char * icalerror_strerror(icalerrorenum e)
Finds the description string for error.
#define icalerrno
Access the current icalerrno value.
Definition icalerror.h:130
void icalmemory_free_buffer(void *buf)
Releases a buffer.
Definition icalmemory.c:353
void * icalmemory_new_buffer(size_t size)
Creates new buffer with the specified size.
Definition icalmemory.c:313
Common memory management routines.