xref: /netbsd-src/share/man/man3/_DIAGASSERT.3 (revision 23c8222edbfb0f0932d88a8351d3a0cf817dfb9e)
1.\"	$NetBSD: _DIAGASSERT.3,v 1.6 2003/06/27 00:04:34 lukem Exp $
2.\"
3.\" Copyright (c) 2001 The NetBSD Foundation, Inc.
4.\" All rights reserved.
5.\"
6.\" This code is derived from software contributed to The NetBSD Foundation
7.\" by Luke Mewburn.
8.\"
9.\" Redistribution and use in source and binary forms, with or without
10.\" modification, are permitted provided that the following conditions
11.\" are met:
12.\" 1. Redistributions of source code must retain the above copyright
13.\"    notice, this list of conditions and the following disclaimer.
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\"    notice, this list of conditions and the following disclaimer in the
16.\"    documentation and/or other materials provided with the distribution.
17.\" 3. All advertising materials mentioning features or use of this software
18.\"    must display the following acknowledgement:
19.\"        This product includes software developed by the NetBSD
20.\"        Foundation, Inc. and its contributors.
21.\" 4. Neither the name of The NetBSD Foundation nor the names of its
22.\"    contributors may be used to endorse or promote products derived
23.\"    from this software without specific prior written permission.
24.\"
25.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
26.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
29.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35.\" POSSIBILITY OF SUCH DAMAGE.
36.\"
37.Dd June 27, 2003
38.Dt _DIAGASSERT 3
39.Os
40.Sh NAME
41.Nm _DIAGASSERT
42.Nd expression verification macro
43.Sh SYNOPSIS
44.In assert.h
45.Fn _DIAGASSERT expression
46.Sh DESCRIPTION
47The
48.Fn _DIAGASSERT
49macro tests the given
50.Ar expression
51and if it is false, one or more of the following may occur:
52.Bl -bullet -offset indent
53.It
54a diagnostic message may be logged to the system logger with
55.Xr syslog 3 .
56This is default behaviour.
57.It
58a diagnostic message may be printed to the
59.Dv stderr
60stream.
61.It
62the calling process will be terminated by calling
63.Xr abort 3 .
64.El
65.Pp
66This behaviour may be changed by setting the
67.Ev LIBC_DIAGASSERT
68environment variable (see below).
69.Pp
70The diagnostic message consists of the text of the expression,
71the name of the source file, the line number and the enclosing
72function.
73.Pp
74If
75.Ar expression
76is true,
77the
78.Fn _DIAGASSERT
79macro does nothing.
80.Pp
81The
82.Fn _DIAGASSERT
83macro is not compiled in by default, and will only be compiled in with the
84.Xr cc 1
85option
86.Fl D_DIAGNOSTIC .
87.Pp
88This macro is used in the various system libraries such as the
89.Lb libc
90to ensure that various library calls are invoked with valid arguments.
91.Sh ENVIRONMENT
92The
93.Ev LIBC_DIAGASSERT
94environment variable can be used to modify the default behaviour of
95logging the assertion to the system logger.
96.Pp
97.Ev LIBC_DIAGASSERT
98may be set to one or more of the following characters:
99.Bl -tag -width xxx -offset indent
100.It a
101.Xr abort 3
102once any assertion messages have been logged and/or printed.
103.It A
104Opposite of
105.Dq a .
106.It e
107Print the assertion message to the
108.Dv stderr
109stream.
110.It E
111Opposite of
112.Dq e .
113.It l
114Log the assertion message with
115.Xr syslog 3
116to the facility
117.Dv user.debug .
118.It L
119Opposite of
120.Dq l .
121.El
122.Sh DIAGNOSTICS
123The diagnostic message has the following format:
124.Bd -literal -offset indent
125"assertion \e"%s\e" failed: file \e"%s\e", line %d, function \e"%s\e"\en",
126	    "expression", __FILE__, __LINE__, __func__
127.Ed
128.Sh SEE ALSO
129.Xr cc 1 ,
130.Xr abort 3 ,
131.Xr assert 3
132.Sh HISTORY
133The
134.Nm _DIAGASSERT
135macro appeared in
136.Nx 1.5 .
137