* Change __assert() function to print failing function name.
* Make the output from assert() look more like the example in the C99
standard.
* SUCH DAMAGE.
*
* @(#)assert.h 8.2 (Berkeley) 1/21/94
+ * $FreeBSD: src/include/assert.h,v 1.6 2007/12/01 19:28:13 phk Exp $
* $DragonFly: src/include/assert.h,v 1.4 2005/04/26 10:41:57 joerg Exp $
*/
+#include <sys/cdefs.h>
+
/*
* Unlike other ANSI header files, <assert.h> may usefully be included
* multiple times, with and without NDEBUG defined.
#define _assert(e) ((void)0)
#else
#define _assert(e) assert(e)
-#define assert(e) ((e) ? (void)0 : __assert(__FILE__, __LINE__, #e))
-#endif
+
+#define assert(e) ((e) ? (void)0 : __assert(__func__, __FILE__, \
+ __LINE__, #e))
+#endif /* NDEBUG */
#undef _DIAGASSERT
#ifdef _DIAGNOSTIC
-#define _DIAGASSERT(e) ((e) ? (void)0 : __diagassert(__FILE__, __LINE__, __func__, #e))
+#define _DIAGASSERT(e) ((e) ? (void)0 : __diagassert(__FILE__, __LINE__, \
+ __func__, #e))
#else
#define _DIAGASSERT(e) ((void)0)
#endif
-#include <sys/cdefs.h>
-
+#ifndef _ASSERT_H_
+#define _ASSERT_H_
__BEGIN_DECLS
-void __assert(const char *, int, const char *);
+void __assert(const char *, const char *, int, const char *);
void __diagassert(const char *, int, const char *, const char *);
__END_DECLS
+#endif /* !_ASSERT_H_ */
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
* SUCH DAMAGE.
*
* @(#)assert.c 8.1 (Berkeley) 6/4/93
+ * $FreeBSD: src/lib/libc/gen/assert.c,v 1.8 2007/01/09 00:27:53 imp Exp $
* $DragonFly: src/lib/libc/gen/assert.c,v 1.5 2005/04/26 10:41:57 joerg Exp $
*/
#include <stdlib.h>
void
-__assert(const char *file, int line, const char *failedexpr)
+__assert(const char *func, const char *file, int line, const char *failedexpr)
{
- fprintf(stderr, "assertion \"%s\" failed: file \"%s\", line %d\n",
- failedexpr, file, line);
+ if (func == NULL) {
+ fprintf(stderr,
+ "Assertion failed: (%s), file %s, line %d.\n", failedexpr,
+ file, line);
+ } else {
+ fprintf(stderr,
+ "Assertion failed: (%s), function %s, file %s, line %d.\n",
+ failedexpr, func, file, line);
+ }
abort();
/* NOTREACHED */
}
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $FreeBSD: src/lib/libstand/assert.c,v 1.2 1999/08/28 00:05:29 peter Exp $
+ * $FreeBSD: src/lib/libstand/assert.c,v 1.7 2001/10/29 07:07:25 mike Exp $
* $DragonFly: src/lib/libstand/assert.c,v 1.3 2004/01/23 14:43:52 joerg Exp $
*/
-#include <stand.h>
#include <assert.h>
+#include "stand.h"
+
void exit(int code);
void
-__assert(const char *file, int line, const char *expression)
+__assert(const char *func, const char *file, int line, const char *expression)
{
- printf("assertion \"%s\" failed: file \"%s\", line %d\n", expression,
- file, line);
+ if (func == NULL) {
+ printf("Assertion failed: (%s), file %s, line %d.\n",
+ expression, file, line);
+ } else {
+ printf("Assertion failed: (%s), function %s, file %s, line "
+ "%d.\n", expression, func, file, line);
+ }
exit(1);
}
.\" SUCH DAMAGE.
.\"
.\" @(#)assert.3 8.1 (Berkeley) 6/9/93
-.\" $FreeBSD: src/share/man/man3/assert.3,v 1.7.2.3 2001/12/17 11:30:11 ru Exp $
+.\" $FreeBSD: src/share/man/man3/assert.3,v 1.15 2002/12/04 18:57:46 ru Exp $
.\" $DragonFly: src/share/man/man3/assert.3,v 1.2 2003/06/17 04:36:58 dillon Exp $
.\"
.Dd January 26, 1999
the calling process is terminated.
A
diagnostic message is written to
-.Em stderr
+.Dv stderr
and the function
.Xr abort 3
is called, effectively terminating the program.
.Xr cc 1
option
.Fl D Ns Dv NDEBUG ) .
-.Sh DIAGNOSTICS
-The following diagnostic message is written to
-.Em stderr
-if
-.Ar expression
-is false:
-.Bd -literal -offset indent
-"assertion \e"%s\e" failed: file \e"%s\e", line %d\en", \e
- "expression", __FILE__, __LINE__);
-.Ed
+.Sh EXAMPLES
+The assertion:
+.Pp
+.Dl "assert(1 == 0);"
+.Pp
+generates a diagnostic message similar to the following:
+.Pp
+.Dl "Assertion failed: (1 == 0), function main, file assertion.c, line 100."
.Sh SEE ALSO
.Xr abort 3
+.Sh STANDARDS
+The
+.Fn assert
+macro conforms to
+.St -isoC-99 .
.Sh HISTORY
An
.Nm