assfail.h revision 272701
1224133Sdim/*- 2224133Sdim * Copyright (c) 2012 Martin Matuska <mm@FreeBSD.org> 3224133Sdim * All rights reserved. 4224133Sdim * 5224133Sdim * Redistribution and use in source and binary forms, with or without 6224133Sdim * modification, are permitted provided that the following conditions 7224133Sdim * are met: 8224133Sdim * 1. Redistributions of source code must retain the above copyright 9224133Sdim * notice, this list of conditions and the following disclaimer. 10224133Sdim * 2. Redistributions in binary form must reproduce the above copyright 11224133Sdim * notice, this list of conditions and the following disclaimer in the 12239462Sdim * documentation and/or other materials provided with the distribution. 13224133Sdim * 14239462Sdim * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND 15224133Sdim * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16239462Sdim * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17224133Sdim * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE 18239462Sdim * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19239462Sdim * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20239462Sdim * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21224133Sdim * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22224133Sdim * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23224133Sdim * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24239462Sdim * SUCH DAMAGE. 25239462Sdim * 26239462Sdim * $FreeBSD: head/sys/cddl/compat/opensolaris/sys/assfail.h 272701 2014-10-07 14:15:50Z avg $ 27239462Sdim */ 28239462Sdim 29239462Sdim#ifndef _OPENSOLARIS_SYS_ASSFAIL_H_ 30239462Sdim#define _OPENSOLARIS_SYS_ASSFAIL_H_ 31239462Sdim 32239462Sdim#include <sys/types.h> 33239462Sdim#ifndef _KERNEL 34239462Sdim#include <stdio.h> 35239462Sdim#include <stdlib.h> 36239462Sdim#endif 37239462Sdim 38239462Sdim#ifdef __cplusplus 39239462Sdimextern "C" { 40239462Sdim#endif 41239462Sdim 42239462Sdim#ifdef _KERNEL 43239462Sdimint assfail(const char *, const char *, int); 44239462Sdimvoid assfail3(const char *, uintmax_t, const char *, uintmax_t, const char *, 45239462Sdim int); 46239462Sdim#else /* !defined(_KERNEL) */ 47239462Sdim 48239462Sdim#ifndef HAVE_ASSFAIL 49239462Sdimextern int aok; 50239462Sdim 51239462Sdimstatic __inline int 52239462Sdim__assfail(const char *expr, const char *file, int line) 53239462Sdim{ 54239462Sdim 55239462Sdim (void)fprintf(stderr, "Assertion failed: (%s), file %s, line %d.\n", 56239462Sdim expr, file, line); 57239462Sdim if (!aok) 58239462Sdim abort(); 59239462Sdim return (0); 60239462Sdim} 61239462Sdim#define assfail __assfail 62239462Sdim#endif 63239462Sdim 64239462Sdim#ifndef HAVE_ASSFAIL3 65239462Sdimextern int aok; 66239462Sdim 67239462Sdimstatic __inline void 68224133Sdim__assfail3(const char *expr, uintmax_t lv, const char *op, uintmax_t rv, 69224133Sdim const char *file, int line) { 70224133Sdim 71224133Sdim (void)fprintf(stderr, 72224133Sdim "Assertion failed: %s (0x%jx %s 0x%jx), file %s, line %d.\n", 73224133Sdim expr, lv, op, rv, file, line); 74224133Sdim if (!aok) 75224133Sdim abort(); 76224133Sdim} 77224133Sdim#define assfail3 __assfail3 78224133Sdim#endif 79224133Sdim 80224133Sdim#endif /* !defined(_KERNEL) */ 81224133Sdim 82224133Sdim#ifdef __cplusplus 83224133Sdim} 84224133Sdim#endif 85224133Sdim 86224133Sdim#endif /* _OPENSOLARIS_SYS_ASSFAIL_H_ */ 87224133Sdim