summaryrefslogtreecommitdiff
path: root/src/assert
diff options
context:
space:
mode:
authorJakob Kaivo <jkk@ung.org>2019-02-08 18:42:39 -0500
committerJakob Kaivo <jkk@ung.org>2019-02-08 18:42:39 -0500
commit7ef8a7379f7f7d09e71ccae2a0b688c3cd80423f (patch)
tree092ab0aed1769117fd7b28b8592f6f96b0e0d5af /src/assert
parent6acf19370e8adff79cd83b257d3f04aeaf2a59dd (diff)
merge sources into single tree
Diffstat (limited to 'src/assert')
-rw-r--r--src/assert/NDEBUG.c14
-rw-r--r--src/assert/__assert.c15
-rw-r--r--src/assert/assert.c44
3 files changed, 73 insertions, 0 deletions
diff --git a/src/assert/NDEBUG.c b/src/assert/NDEBUG.c
new file mode 100644
index 00000000..b09e73ce
--- /dev/null
+++ b/src/assert/NDEBUG.c
@@ -0,0 +1,14 @@
+/* #undef NDEBUG */
+
+#define NDEBUG /** control program diagnostics **/
+
+/***
+THIS() is not defined by the compiler or any header. If it is defined
+by the programmer before including HEADER(assert.h), it causes
+FUNCTION(assert) to be a void statement. Otherwise, FUNCTION(assert) has
+its normal behavior.
+***/
+
+/*
+STDC(1)
+*/
diff --git a/src/assert/__assert.c b/src/assert/__assert.c
new file mode 100644
index 00000000..630fdec1
--- /dev/null
+++ b/src/assert/__assert.c
@@ -0,0 +1,15 @@
+#include <assert.h>
+#include "stdio.h"
+#include "stdlib.h"
+
+void __assert(const char *expr, const char *file, int line, const char *func)
+{
+ if (func) {
+ fprintf(stderr, "Assertion failed: %s (%s:%d:%s())\n", expr,
+ file, line, func);
+ } else {
+ fprintf(stderr, "Assertion failed: %s (%s:%d)\n", expr, file,
+ line);
+ }
+ abort();
+}
diff --git a/src/assert/assert.c b/src/assert/assert.c
new file mode 100644
index 00000000..65e4ea6e
--- /dev/null
+++ b/src/assert/assert.c
@@ -0,0 +1,44 @@
+#include <assert.h>
+
+#undef assert
+
+#ifdef NDEBUG
+
+#define assert(ignore) ((void)0)
+
+#else
+
+#if __STDC_VERSION__ < 199901L
+#define __func__ ((char*)0)
+#endif
+
+#define assert(__exp__) \
+ ((void)(__exp__ ? 0 : __assert(#__exp__, __FILE__, __LINE__, __func__)))
+
+#endif
+
+/* in c89 - void assert(int expression); */
+/* in c99 - void assert(/scalar/ expression); */
+
+/** insert program diagnostics **/
+
+/***
+adds mandatory checks to programs. If ARGUMENT(expression) is false,
+FUNCTION(assert) prints a diagnostic message to IDENTIFIER(stderr). The
+message includes the text of the failed assertion as well as the file name and
+line number of the source where the assertion failed. Compilers supporting
+std(C99) or higher will also include the name of the function in which the
+assertion failed. After printing the diagnostic message, THIS()
+causes abnormal program termination by calling FUNCTION(abort).
+
+If the macro IDENTIFIER(NDEBUG) is defined, THIS() is
+defined as DEFINITION(((void)0)).
+***/
+
+/*
+PROTOTYPE(void assert(int expression);)
+IMPLEMENTATION(The format of the diagnostic message, TODO: document this here)
+UNDEFINED(The THIS() macro is suppressed)
+UNDEFINED(ARGUMENT(expression) does not have a scalar type)
+STDC(1)
+*/