1196992Spjd/*-
2196992Spjd * Copyright (c) 2009 Pawel Jakub Dawidek <pjd@FreeBSD.org>
3196992Spjd * All rights reserved.
4196992Spjd *
5196992Spjd * Redistribution and use in source and binary forms, with or without
6196992Spjd * modification, are permitted provided that the following conditions
7196992Spjd * are met:
8196992Spjd * 1. Redistributions of source code must retain the above copyright
9196992Spjd *    notice, this list of conditions and the following disclaimer.
10196992Spjd * 2. Redistributions in binary form must reproduce the above copyright
11196992Spjd *    notice, this list of conditions and the following disclaimer in the
12196992Spjd *    documentation and/or other materials provided with the distribution.
13196992Spjd *
14196992Spjd * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
15196992Spjd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16196992Spjd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17196992Spjd * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
18196992Spjd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19196992Spjd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20196992Spjd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21196992Spjd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22196992Spjd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23196992Spjd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24196992Spjd * SUCH DAMAGE.
25196992Spjd *
26196992Spjd * $FreeBSD$
27196992Spjd */
28196992Spjd
29196992Spjd#undef assert
30196992Spjd#undef _assert
31196992Spjd
32196992Spjd#ifdef NDEBUG
33196992Spjd#define	assert(e)	((void)0)
34196992Spjd#define	_assert(e)	((void)0)
35196992Spjd#else
36196992Spjd#define	_assert(e)	assert(e)
37196992Spjd
38196992Spjd#define	assert(e)	((e) ? (void)0 : __assert(#e, __FILE__, __LINE__))
39196992Spjd#endif /* NDEBUG */
40196992Spjd
41196992Spjd#ifndef _ASSERT_H_
42196992Spjd#define _ASSERT_H_
43196992Spjd#include <stdio.h>
44196992Spjd#include <stdlib.h>
45196992Spjd
46222950Sgibbs#ifdef  __cplusplus
47222950Sgibbsextern "C" {
48222950Sgibbs#endif
49222950Sgibbs
50196992Spjdstatic __inline void
51196992Spjd__assert(const char *expr, const char *file, int line)
52196992Spjd{
53196992Spjd
54196992Spjd	(void)fprintf(stderr, "Assertion failed: (%s), file %s, line %d.\n",
55196992Spjd	    expr, file, line);
56196992Spjd	abort();
57196992Spjd	/* NOTREACHED */
58196992Spjd}
59222950Sgibbs
60222950Sgibbs#ifdef  __cplusplus
61222950Sgibbs}
62222950Sgibbs#endif
63222950Sgibbs
64196992Spjd#endif /* !_ASSERT_H_ */
65