aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Huth <thuth@redhat.com>2018-06-05 12:11:47 +0200
committerAlexey Kardashevskiy <aik@ozlabs.ru>2018-06-07 16:38:42 +1000
commit12278e72d54d6c4be37a9cc25d97db28d3f227aa (patch)
tree8e7aa5ca8b5b78e83df280622ca37ae393d0d6e3
parent64c526a6020c3042e3b2a505d5f5f11478d5f2cb (diff)
downloadSLOF-12278e72d54d6c4be37a9cc25d97db28d3f227aa.zip
SLOF-12278e72d54d6c4be37a9cc25d97db28d3f227aa.tar.gz
SLOF-12278e72d54d6c4be37a9cc25d97db28d3f227aa.tar.bz2
libc: Add a simple implementation of an assert() function
... useful for "this should never happen" situations, where you want to make sure that it really never happens. Signed-off-by: Thomas Huth <thuth@redhat.com> Reviewed-by: Greg Kurz <groug@kaod.org> [aik: removed extra ';' and empty line] Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
-rw-r--r--lib/libc/include/assert.h36
1 files changed, 36 insertions, 0 deletions
diff --git a/lib/libc/include/assert.h b/lib/libc/include/assert.h
new file mode 100644
index 0000000..01434da
--- /dev/null
+++ b/lib/libc/include/assert.h
@@ -0,0 +1,36 @@
+/*****************************************************************************
+ * assert() macro definition
+ *
+ * Copyright 2018 Red Hat, Inc.
+ *
+ * This program and the accompanying materials are made available under
+ * the terms of the BSD License which accompanies this distribution, and
+ * is available at http://www.opensource.org/licenses/bsd-license.php
+ *
+ * Contributors:
+ * Thomas Huth, Red Hat Inc. - initial implementation
+ *****************************************************************************/
+
+#ifndef SLIMLINE_ASSERT_H
+#define SLIMLINE_ASSERT_H
+
+#ifdef NDEBUG
+
+#define assert(cond) (void)
+
+#else
+
+#define assert(cond) \
+ do { \
+ if (!(cond)) { \
+ fprintf(stderr, \
+ "ERROR: Assertion '" #cond "' failed!\n" \
+ "(function %s, file " __FILE__ ", line %i)\n", \
+ __func__, __LINE__); \
+ while (1) {} \
+ } \
+ } while (0)
+
+#endif
+
+#endif /* SLIMLINE_ASSERT_H */