aboutsummaryrefslogtreecommitdiff
path: root/src/microhttpd/mhd_panic.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/microhttpd/mhd_panic.h')
-rw-r--r--src/microhttpd/mhd_panic.h82
1 files changed, 82 insertions, 0 deletions
diff --git a/src/microhttpd/mhd_panic.h b/src/microhttpd/mhd_panic.h
new file mode 100644
index 00000000..623639b4
--- /dev/null
+++ b/src/microhttpd/mhd_panic.h
@@ -0,0 +1,82 @@
1/*
2 This file is part of libmicrohttpd
3 Copyright (C) 2007-2018 Daniel Pittman and Christian Grothoff
4 Copyright (C) 2014-2022 Evgeny Grin (Karlson2k)
5
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
10
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public
17 License along with this library; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19*/
20
21/**
22 * @file microhttpd/mhd_panic.h
23 * @brief Declaration and macros for MHD_panic()
24 * @author Daniel Pittman
25 * @author Christian Grothoff
26 * @author Karlson2k (Evgeny Grin)
27 */
28
29#ifndef MHD_PANIC_H
30#define MHD_PANIC_H 1
31
32#include "mhd_options.h"
33
34#ifdef MHD_PANIC
35/* Override any possible defined MHD_PANIC macro with proper one */
36#undef MHD_PANIC
37#endif /* MHD_PANIC */
38
39/* If we have Clang or gcc >= 4.5, use __builtin_unreachable() */
40#if defined(__clang__) || (__GNUC__ > 4) || \
41 (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)
42#define BUILTIN_NOT_REACHED __builtin_unreachable ()
43#elif defined(_MSC_FULL_VER)
44#define BUILTIN_NOT_REACHED __assume (0)
45#else
46#define BUILTIN_NOT_REACHED
47#endif
48
49/* The MHD_PanicCallback type, but without main header. */
50/**
51 * Handler for fatal errors.
52 */
53extern void
54(*mhd_panic) (void *cls,
55 const char *file,
56 unsigned int line,
57 const char *reason);
58
59/**
60 * Closure argument for "mhd_panic".
61 */
62extern void *mhd_panic_cls;
63
64#ifdef HAVE_MESSAGES
65/**
66 * Trigger 'panic' action based on fatal errors.
67 *
68 * @param msg error message (const char *)
69 */
70#define MHD_PANIC(msg) do { mhd_panic (mhd_panic_cls, __FILE__, __LINE__, msg); \
71 BUILTIN_NOT_REACHED; } while (0)
72#else
73/**
74 * Trigger 'panic' action based on fatal errors.
75 *
76 * @param msg error message (const char *)
77 */
78#define MHD_PANIC(msg) do { mhd_panic (mhd_panic_cls, __FILE__, __LINE__, NULL); \
79 BUILTIN_NOT_REACHED; } while (0)
80#endif
81
82#endif /* MHD_PANIC_H */