Mercurial > molko
comparison libmlk-core/core/panic.c @ 243:71b3b7036de7
misc: lot of cleanups,
- prefix libraries with libmlk,
- move assets from source directories closes #2520,
- prefix header guards closes #2519
author | David Demelier <markand@malikania.fr> |
---|---|
date | Sat, 28 Nov 2020 22:37:30 +0100 |
parents | libcore/core/panic.c@76afe639fd72 |
children | c4da052c0def |
comparison
equal
deleted
inserted
replaced
242:4c24604efcab | 243:71b3b7036de7 |
---|---|
1 /* | |
2 * panic.c -- unrecoverable error handling | |
3 * | |
4 * Copyright (c) 2020 David Demelier <markand@malikania.fr> | |
5 * | |
6 * Permission to use, copy, modify, and/or distribute this software for any | |
7 * purpose with or without fee is hereby granted, provided that the above | |
8 * copyright notice and this permission notice appear in all copies. | |
9 * | |
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | |
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | |
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | |
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | |
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | |
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | |
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
17 */ | |
18 | |
19 #include <assert.h> | |
20 #include <stdio.h> | |
21 #include <stdlib.h> | |
22 | |
23 #include "core_p.h" | |
24 #include "error.h" | |
25 #include "panic.h" | |
26 | |
27 static void | |
28 terminate(void) | |
29 { | |
30 fprintf(stderr, _("abort: %s\n"), error()); | |
31 abort(); | |
32 exit(1); | |
33 } | |
34 | |
35 void (*panic_handler)(void) = terminate; | |
36 | |
37 void | |
38 panicf(const char *fmt, ...) | |
39 { | |
40 assert(fmt); | |
41 | |
42 va_list ap; | |
43 | |
44 /* | |
45 * Store the error before calling panic because va_end would not be | |
46 * called. | |
47 */ | |
48 va_start(ap, fmt); | |
49 verrorf(fmt, ap); | |
50 va_end(ap); | |
51 | |
52 panic(); | |
53 } | |
54 | |
55 void | |
56 vpanicf(const char *fmt, va_list ap) | |
57 { | |
58 assert(fmt); | |
59 assert(panic_handler); | |
60 | |
61 verrorf(fmt, ap); | |
62 panic(); | |
63 } | |
64 | |
65 void | |
66 panic(void) | |
67 { | |
68 assert(panic_handler); | |
69 | |
70 panic_handler(); | |
71 | |
72 /* | |
73 * This should not happen, if it does it means the user did not fully | |
74 * satisfied the constraint of panic_handler. | |
75 */ | |
76 fprintf(stderr, _("abort: panic handler returned\n")); | |
77 exit(1); | |
78 } |