libc

A portable C Library
Log | Files | Refs | README

commit be1f980821cd86c02ce64e89479ce2e9bde34d79
parent c3edec6bebf4f1db6810fd0457d20adba2dde093
Author: zerous Naveen Narayanan <zerous@nocebo.space>
Date:   Tue, 12 Nov 2019 16:47:58 +0100

Add assert

Diffstat:
A__assert.c | 11+++++++++++
Aassert.h | 9+++++++++
2 files changed, 20 insertions(+), 0 deletions(-)

diff --git a/__assert.c b/__assert.c @@ -0,0 +1,11 @@ +#include <stdio.h> +#include <stdlib.h> +#include "assert.h" + +void +__assert(char *mesg) +{ + fputs(mesg,stderr); + fputs(" -- assertion failed\n",stderr); + abort(); +} diff --git a/assert.h b/assert.h @@ -0,0 +1,9 @@ +#undef assert +#ifdef NDEBUG +#define assert(exp) ((void)0) +#else +#define _STR(x) _VAL(x) +#define _VAL(x) #x +#define assert(exp) ((exp) ? (void)0 \ + : __assert(#exp" : "__FILE__" : "_STR(__LINE__))); +#endif