11.27Sriastrad/*	$NetBSD: assert.h,v 1.27 2025/03/29 01:43:38 riastradh Exp $	*/
21.6Scgd
31.5Scgd/*-
41.5Scgd * Copyright (c) 1992, 1993
51.5Scgd *	The Regents of the University of California.  All rights reserved.
61.5Scgd * (c) UNIX System Laboratories, Inc.
71.5Scgd * All or some portions of this file are derived from material licensed
81.5Scgd * to the University of California by American Telephone and Telegraph
91.5Scgd * Co. or Unix System Laboratories, Inc. and are reproduced herein with
101.5Scgd * the permission of UNIX System Laboratories, Inc.
111.5Scgd *
121.5Scgd * Redistribution and use in source and binary forms, with or without
131.5Scgd * modification, are permitted provided that the following conditions
141.5Scgd * are met:
151.5Scgd * 1. Redistributions of source code must retain the above copyright
161.5Scgd *    notice, this list of conditions and the following disclaimer.
171.5Scgd * 2. Redistributions in binary form must reproduce the above copyright
181.5Scgd *    notice, this list of conditions and the following disclaimer in the
191.5Scgd *    documentation and/or other materials provided with the distribution.
201.15Sagc * 3. Neither the name of the University nor the names of its contributors
211.5Scgd *    may be used to endorse or promote products derived from this software
221.5Scgd *    without specific prior written permission.
231.5Scgd *
241.5Scgd * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
251.5Scgd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
261.5Scgd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
271.5Scgd * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
281.5Scgd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
291.5Scgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
301.5Scgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
311.5Scgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
321.5Scgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
331.5Scgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
341.5Scgd * SUCH DAMAGE.
351.5Scgd *
361.6Scgd *	@(#)assert.h	8.2 (Berkeley) 1/21/94
371.5Scgd */
381.5Scgd
391.5Scgd/*
401.5Scgd * Unlike other ANSI header files, <assert.h> may usefully be included
411.5Scgd * multiple times, with and without NDEBUG defined.
421.5Scgd */
431.5Scgd
441.12Skleink#include <sys/cdefs.h>
451.13Sbjh21#include <sys/featuretest.h>
461.20Schristos#include <sys/null.h>
471.12Skleink
481.5Scgd#undef assert
491.5Scgd
501.5Scgd#ifdef NDEBUG
511.26Srillig# define assert(e)	(__static_cast(void,0))
521.7Schristos#else /* !NDEBUG */
531.9Skleink# if __STDC__
541.10Skleink#  define assert(e)							\
551.27Sriastrad	(__predict_true(e) ? __static_cast(void,0)			\
561.27Sriastrad	    : __assert13(__FILE__, __LINE__, __assert_function__, #e))
571.7Schristos# else	/* PCC */
581.10Skleink#  define assert(e)							\
591.27Sriastrad	(__predict_true(e) ? __static_cast(void,0)			\
601.27Sriastrad	    : __assert13(__FILE__, __LINE__, __assert_function__, "e"))
611.9Skleink# endif /* !__STDC__ */
621.7Schristos#endif /* NDEBUG */
631.13Sbjh21
641.8Slukem#undef _DIAGASSERT
651.8Slukem#if !defined(_DIAGNOSTIC)
661.26Srillig# define _DIAGASSERT(e) (__static_cast(void,0))
671.8Slukem#else /* _DIAGNOSTIC */
681.9Skleink# if __STDC__
691.10Skleink#  define _DIAGASSERT(e)						\
701.27Sriastrad	(__predict_true(e) ? __static_cast(void,0)			\
711.27Sriastrad	    : __diagassert13(__FILE__, __LINE__, __assert_function__, #e))
721.8Slukem# else	/* !__STDC__ */
731.10Skleink#  define _DIAGASSERT(e)	 					\
741.27Sriastrad	(__predict_true(e) ? __static_cast(void,0)			\
751.27Sriastrad	    : __diagassert13(__FILE__, __LINE__, __assert_function__, "e"))
761.8Slukem# endif
771.8Slukem#endif /* _DIAGNOSTIC */
781.8Slukem
791.8Slukem
801.26Srillig#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
811.10Skleink#define	__assert_function__	__func__
821.10Skleink#elif __GNUC_PREREQ__(2, 6)
831.10Skleink#define	__assert_function__	__PRETTY_FUNCTION__
841.10Skleink#else
851.12Skleink#define	__assert_function__	(__static_cast(const void *,0))
861.10Skleink#endif
871.10Skleink
881.11Schristos#ifndef __ASSERT_DECLARED
891.11Schristos#define __ASSERT_DECLARED
901.5Scgd__BEGIN_DECLS
911.21Sjoerg__dead void __assert(const char *, int, const char *);
921.21Sjoerg__dead void __assert13(const char *, int, const char *, const char *);
931.18Sperryvoid __diagassert(const char *, int, const char *);
941.18Sperryvoid __diagassert13(const char *, int, const char *, const char *);
951.5Scgd__END_DECLS
961.11Schristos#endif /* __ASSERT_DECLARED */
971.22Skamil
981.25Skamil#if defined(_ISOC11_SOURCE) || (__STDC_VERSION__ - 0) >= 201101L
991.24Skamil#ifndef static_assert
1001.22Skamil#define static_assert _Static_assert
1011.22Skamil#endif /* static_assert */
1021.22Skamil#endif
103