assfail.h revision 240415
153642Sguido/*- 2145522Sdarrenr * Copyright (c) 2012 Martin Matuska <mm@FreeBSD.org> 353642Sguido * All rights reserved. 480482Sdarrenr * 553642Sguido * Redistribution and use in source and binary forms, with or without 653642Sguido * modification, are permitted provided that the following conditions 757126Sguido * are met: 8172776Sdarrenr * 1. Redistributions of source code must retain the above copyright 953642Sguido * notice, this list of conditions and the following disclaimer. 1053642Sguido * 2. Redistributions in binary form must reproduce the above copyright 1153642Sguido * notice, this list of conditions and the following disclaimer in the 1253642Sguido * documentation and/or other materials provided with the distribution. 1353642Sguido * 1453642Sguido * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND 1553642Sguido * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1653642Sguido * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1753642Sguido * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE 1853642Sguido * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 1953642Sguido * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2053642Sguido * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2153642Sguido * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2253642Sguido * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2353642Sguido * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2453642Sguido * SUCH DAMAGE. 2553642Sguido * 2653642Sguido * $FreeBSD: head/sys/cddl/compat/opensolaris/sys/assfail.h 240415 2012-09-12 18:05:43Z mm $ 2753642Sguido */ 2853642Sguido 2953642Sguido#ifndef _OPENSOLARIS_SYS_ASSFAIL_H_ 3053642Sguido#define _OPENSOLARIS_SYS_ASSFAIL_H_ 3153642Sguido 3253642Sguido#include <sys/types.h> 3353642Sguido#ifndef _KERNEL 3453642Sguido#include <stdio.h> 35145522Sdarrenr#include <stdlib.h> 36145522Sdarrenr#endif 37145522Sdarrenr 38173181Sdarrenr#ifdef __cplusplus 39145522Sdarrenrextern "C" { 40145522Sdarrenr#endif 41145522Sdarrenr 42145522Sdarrenr#ifdef _KERNEL 43145522Sdarrenrint assfail(const char *, const char *, int); 44145522Sdarrenrvoid assfail3(const char *, uintmax_t, const char *, uintmax_t, const char *, 45145522Sdarrenr int); 46145522Sdarrenr#else /* !defined(_KERNEL) */ 47145522Sdarrenr 48145522Sdarrenr#ifndef HAVE_ASSFAIL 49145522Sdarrenrstatic __inline int 50145522Sdarrenr__assfail(const char *expr, const char *file, int line) 51145522Sdarrenr{ 52145522Sdarrenr 53145522Sdarrenr (void)fprintf(stderr, "Assertion failed: (%s), file %s, line %d.\n", 54145522Sdarrenr expr, file, line); 55145522Sdarrenr abort(); 56145522Sdarrenr /* NOTREACHED */ 57145522Sdarrenr return (0); 58145522Sdarrenr} 59145522Sdarrenr#define assfail __assfail 60145522Sdarrenr#endif 61145522Sdarrenr 62145522Sdarrenr#ifndef HAVE_ASSFAIL3 63145522Sdarrenrstatic __inline void 64145522Sdarrenr__assfail3(const char *expr, uintmax_t lv, const char *op, uintmax_t rv, 65145522Sdarrenr const char *file, int line) { 66145522Sdarrenr 67145522Sdarrenr (void)fprintf(stderr, 68145522Sdarrenr "Assertion failed: %s (0x%jx %s 0x%jx), file %s, line %d.\n", 69145522Sdarrenr expr, lv, op, rv, file, line); 70145522Sdarrenr abort(); 7153642Sguido /* NOTREACHED */ 72145522Sdarrenr} 73145522Sdarrenr#define assfail3 __assfail3 7453642Sguido#endif 7553642Sguido 7653642Sguido#endif /* !defined(_KERNEL) */ 7753642Sguido 7853642Sguido#ifdef __cplusplus 7953642Sguido} 80145522Sdarrenr#endif 81145522Sdarrenr 8292685Sdarrenr#endif /* _OPENSOLARIS_SYS_ASSFAIL_H_ */ 8392685Sdarrenr