aboutsummaryrefslogtreecommitdiff
path: root/src/constraint_handler.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/constraint_handler.c66
1 files changed, 66 insertions, 0 deletions
diff --git a/src/constraint_handler.c b/src/constraint_handler.c
new file mode 100644
index 0000000..ca4e9d2
--- /dev/null
+++ b/src/constraint_handler.c
@@ -0,0 +1,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)
+{}