Libical API Documentation
4.0 STABLE VERSION
[Visit the v3.0 documentation]
Toggle main menu visibility
Loading...
Searching...
No Matches
src
libical
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
29
static
ICAL_GLOBAL_VAR
bool
icalerror_errors_are_fatal =
false
;
30
31
void
icalerror_set_errors_are_fatal
(
bool
fatal)
32
{
33
icalerror_errors_are_fatal = fatal;
34
}
35
36
bool
icalerror_get_errors_are_fatal
(
void
)
37
{
38
return
icalerror_errors_are_fatal;
39
}
40
41
#if ICAL_SYNC_MODE == ICAL_SYNC_MODE_PTHREAD
42
#include <pthread.h>
43
44
static
pthread_key_t icalerrno_key;
45
static
pthread_once_t icalerrno_key_once = PTHREAD_ONCE_INIT;
46
47
static
void
icalerrno_destroy(
void
*buf)
48
{
49
icalmemory_free_buffer
(buf);
50
pthread_setspecific(icalerrno_key, NULL);
51
}
52
53
static
void
icalerrno_key_alloc(
void
)
54
{
55
pthread_key_create(&icalerrno_key, icalerrno_destroy);
56
}
57
58
icalerrorenum
*
icalerror_icalerrno
(
void
)
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
76
static
ICAL_GLOBAL_VAR
icalerrorenum
icalerrno_storage =
ICAL_NO_ERROR
;
77
78
icalerrorenum
*
icalerror_icalerrno
(
void
)
79
{
80
return
&icalerrno_storage;
81
}
82
83
#endif
84
85
void
icalerror_clear_errno
(
void
)
86
{
87
icalerrno
=
ICAL_NO_ERROR
;
88
}
89
90
void
icalerror_set_errno
(
icalerrorenum
x)
91
{
92
icalerrno
= x;
93
if
(
icalerror_get_error_state
(x) ==
ICAL_ERROR_FATAL
||
94
(
icalerror_get_error_state
(x) ==
ICAL_ERROR_DEFAULT
&& icalerror_errors_are_fatal)) {
95
icalerror_warn(
icalerror_strerror
(x));
96
icalerror_backtrace
();
97
icalassert(0);
98
}
99
}
100
101
void
icalerror_backtrace
(
void
)
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
}
icalerror_set_errors_are_fatal
void icalerror_set_errors_are_fatal(bool fatal)
Change if errors are fatal.
Definition
icalerror.c:31
icalerror_icalerrno
icalerrorenum * icalerror_icalerrno(void)
Returns the current icalerrno value.
Definition
icalerror.c:58
icalerror_get_errors_are_fatal
bool icalerror_get_errors_are_fatal(void)
Determine if errors are fatal.
Definition
icalerror.c:36
icalerror_backtrace
void icalerror_backtrace(void)
Prints backtrace.
Definition
icalerror.c:101
icalerror_set_errno
void icalerror_set_errno(icalerrorenum x)
Sets the icalerrno to a given error.
Definition
icalerror.c:90
icalerror_clear_errno
void icalerror_clear_errno(void)
Resets icalerrno to ICAL_NO_ERROR.
Definition
icalerror.c:85
icalerror.h
Error handling for libical.
ICAL_ERROR_FATAL
@ ICAL_ERROR_FATAL
Definition
icalerror.h:91
ICAL_ERROR_DEFAULT
@ ICAL_ERROR_DEFAULT
Definition
icalerror.h:97
icalerror_get_error_state
icalerrorstate icalerror_get_error_state(icalerrorenum error)
Gets the error state (severity) for a given error.
icalerrorenum
icalerrorenum
Represents the different types of errors that can be triggered in libical.
Definition
icalerror.h:42
ICAL_NO_ERROR
@ ICAL_NO_ERROR
Definition
icalerror.h:44
icalerror_strerror
const char * icalerror_strerror(icalerrorenum e)
Finds the description string for error.
icalerrno
#define icalerrno
Access the current icalerrno value.
Definition
icalerror.h:133
icalmemory_free_buffer
void icalmemory_free_buffer(void *buf)
Releases a buffer.
Definition
icalmemory.c:355
icalmemory_new_buffer
void * icalmemory_new_buffer(size_t size)
Creates new buffer with the specified size.
Definition
icalmemory.c:315
icalmemory.h
Common memory management routines.
Generated on
for Libical API Documentation by
1.18.0