1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
/* constraint_handler.c
*
* Copyright 2024 axtlos <axtlos@disroot.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* SPDX-License-Identifier: LGPL-3.0-only
*/
#define __STDC_WANT_LIB_EXT1__ 1
#include "extlib.h"
static constraint_handler_t *_cnstrnt_handler = NULL;
constraint_handler_t
set_constraint_handler_s (constraint_handler_t handler)
{
constraint_handler_t *new, *old, ret;
new = malloc (sizeof (constraint_handler_t));
if (!new) return NULL;
*new = handler;
old = _cnstrnt_handler;
_cnstrnt_handler = new;
if (!old)
ret = NULL;
else {
ret = *old;
free (old);
}
return ret;
}
void
throw_constraint_handler_s (const char * restrict msg, errno_t error)
{
constraint_handler_t ch;
ch = _cnstrnt_handler != NULL ? *_cnstrnt_handler : NULL;
if (ch != NULL)
ch (msg, NULL, error);
}
void
abort_handler_s (const char *restrict msg, void * restrict ptr, errno_t error)
{
static const char abrt_msg[] = "abort_handler: ";
fprintf (stderr, "%s", abrt_msg);
fprintf (stderr, "%s\n", msg);
abort ();
}
void
ignore_handler_s (const char * restrict msg, void * restrict ptr, errno_t error)
{}
|