Path: blob/master/waterbox/libc/functions/_PDCLIB/assert.c
2 views
/* _PDCLIB_assert( char const * )12This file is part of the Public Domain C Library (PDCLib).3Permission is granted to use, modify, and / or redistribute at will.4*/56#include <stdio.h>7#include <stdlib.h>8#include <assert.h>910#ifndef REGTEST1112#include "_PDCLIB_aux.h"1314void _PDCLIB_assert99( char const * const message1, char const * const function, char const * const message2 )15{16fputs( message1, stderr );17fputs( function, stderr );18fputs( message2, stderr );19abort();20}2122void _PDCLIB_assert89( char const * const message )23{24fputs( message, stderr );25abort();26}2728#endif2930#ifdef TEST31#include "_PDCLIB_test.h"32#include <signal.h>3334static int EXPECTED_ABORT = 0;35static int UNEXPECTED_ABORT = 1;3637static void aborthandler( int sig )38{39TESTCASE( ! EXPECTED_ABORT );40exit( (signed int)TEST_RESULTS );41}4243#define NDEBUG44#include <assert.h>4546static int disabled_test( void )47{48int i = 0;49assert( i == 0 ); /* NDEBUG set, condition met */50assert( i == 1 ); /* NDEBUG set, condition fails */51return i;52}5354#undef NDEBUG55#include <assert.h>5657int main( void )58{59TESTCASE( signal( SIGABRT, &aborthandler ) != SIG_ERR );60TESTCASE( disabled_test() == 0 );61assert( UNEXPECTED_ABORT ); /* NDEBUG not set, condition met */62assert( EXPECTED_ABORT ); /* NDEBUG not set, condition fails - should abort */63return TEST_RESULTS;64}6566#endif676869