assfail.h revision 240415
1235537Sgber/*-
2235537Sgber * Copyright (c) 2012 Martin Matuska <mm@FreeBSD.org>
3235537Sgber * All rights reserved.
4235537Sgber *
5235537Sgber * Redistribution and use in source and binary forms, with or without
6235537Sgber * modification, are permitted provided that the following conditions
7235537Sgber * are met:
8235537Sgber * 1. Redistributions of source code must retain the above copyright
9235537Sgber *    notice, this list of conditions and the following disclaimer.
10235537Sgber * 2. Redistributions in binary form must reproduce the above copyright
11235537Sgber *    notice, this list of conditions and the following disclaimer in the
12235537Sgber *    documentation and/or other materials provided with the distribution.
13235537Sgber *
14235537Sgber * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
15235537Sgber * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16235537Sgber * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17235537Sgber * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
18235537Sgber * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19235537Sgber * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20235537Sgber * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21235537Sgber * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22235537Sgber * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23235537Sgber * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24235537Sgber * SUCH DAMAGE.
25235537Sgber *
26235537Sgber * $FreeBSD: head/sys/cddl/compat/opensolaris/sys/assfail.h 240415 2012-09-12 18:05:43Z mm $
27235537Sgber */
28235537Sgber
29235537Sgber#ifndef _OPENSOLARIS_SYS_ASSFAIL_H_
30235537Sgber#define	_OPENSOLARIS_SYS_ASSFAIL_H_
31235537Sgber
32235537Sgber#include <sys/types.h>
33235537Sgber#ifndef _KERNEL
34235537Sgber#include <stdio.h>
35235537Sgber#include <stdlib.h>
36235537Sgber#endif
37235537Sgber
38235537Sgber#ifdef	__cplusplus
39235537Sgberextern "C" {
40235537Sgber#endif
41235537Sgber
42235537Sgber#ifdef _KERNEL
43235537Sgberint assfail(const char *, const char *, int);
44235537Sgbervoid assfail3(const char *, uintmax_t, const char *, uintmax_t, const char *,
45235537Sgber    int);
46235537Sgber#else	/* !defined(_KERNEL) */
47235537Sgber
48235537Sgber#ifndef HAVE_ASSFAIL
49235537Sgberstatic __inline int
50235537Sgber__assfail(const char *expr, const char *file, int line)
51235537Sgber{
52235537Sgber
53235537Sgber	(void)fprintf(stderr, "Assertion failed: (%s), file %s, line %d.\n",
54235537Sgber	    expr, file, line);
55235537Sgber	abort();
56235537Sgber	/* NOTREACHED */
57235537Sgber	return (0);
58235537Sgber}
59235537Sgber#define assfail __assfail
60235537Sgber#endif
61241844Seadler
62235537Sgber#ifndef HAVE_ASSFAIL3
63235537Sgberstatic __inline void
64235537Sgber__assfail3(const char *expr, uintmax_t lv, const char *op, uintmax_t rv,
65235537Sgber    const char *file, int line) {
66235537Sgber
67235537Sgber	(void)fprintf(stderr,
68235537Sgber	    "Assertion failed: %s (0x%jx %s 0x%jx), file %s, line %d.\n",
69235537Sgber	    expr, lv, op, rv, file, line);
70235537Sgber        abort();
71235537Sgber        /* NOTREACHED */
72235537Sgber}
73235537Sgber#define assfail3 __assfail3
74235537Sgber#endif
75235537Sgber
76235537Sgber#endif	/* !defined(_KERNEL) */
77235537Sgber
78235537Sgber#ifdef	__cplusplus
79235537Sgber}
80235537Sgber#endif
81235537Sgber
82235537Sgber#endif	/* _OPENSOLARIS_SYS_ASSFAIL_H_ */
83235537Sgber