]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/bind9/lib/isc/assertions.c
add -n option to suppress clearing the build tree and add -DNO_CLEAN
[FreeBSD/FreeBSD.git] / contrib / bind9 / lib / isc / assertions.c
1 /*
2  * Copyright (C) 2004, 2005  Internet Systems Consortium, Inc. ("ISC")
3  * Copyright (C) 1997-2001  Internet Software Consortium.
4  *
5  * Permission to use, copy, modify, and distribute this software for any
6  * purpose with or without fee is hereby granted, provided that the above
7  * copyright notice and this permission notice appear in all copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
10  * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11  * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
12  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15  * PERFORMANCE OF THIS SOFTWARE.
16  */
17
18 /* $Id: assertions.c,v 1.17.18.2 2005/04/29 00:16:44 marka Exp $ */
19
20 /*! \file */
21
22 #include <config.h>
23
24 #include <stdio.h>
25 #include <stdlib.h>
26
27 #include <isc/assertions.h>
28 #include <isc/msgs.h>
29
30 /*%
31  * Forward.
32  */
33 static void
34 default_callback(const char *, int, isc_assertiontype_t, const char *);
35
36 /*%
37  * Public.
38  */
39
40 LIBISC_EXTERNAL_DATA isc_assertioncallback_t isc_assertion_failed =
41                                              default_callback;
42
43 /*% Set callback. */
44 void
45 isc_assertion_setcallback(isc_assertioncallback_t cb) {
46         if (cb == NULL)
47                 isc_assertion_failed = default_callback;
48         else
49                 isc_assertion_failed = cb;
50 }
51
52 /*% Type to Text */
53 const char *
54 isc_assertion_typetotext(isc_assertiontype_t type) {
55         const char *result;
56
57         /*
58          * These strings have purposefully not been internationalized
59          * because they are considered to essentially be keywords of
60          * the ISC development environment.
61          */
62         switch (type) {
63         case isc_assertiontype_require:
64                 result = "REQUIRE";
65                 break;
66         case isc_assertiontype_ensure:
67                 result = "ENSURE";
68                 break;
69         case isc_assertiontype_insist:
70                 result = "INSIST";
71                 break;
72         case isc_assertiontype_invariant:
73                 result = "INVARIANT";
74                 break;
75         default:
76                 result = NULL;
77         }
78         return (result);
79 }
80
81 /*
82  * Private.
83  */
84
85 static void
86 default_callback(const char *file, int line, isc_assertiontype_t type,
87                  const char *cond)
88 {
89         fprintf(stderr, "%s:%d: %s(%s) %s.\n",
90                 file, line, isc_assertion_typetotext(type), cond,
91                 isc_msgcat_get(isc_msgcat, ISC_MSGSET_GENERAL,
92                                ISC_MSG_FAILED, "failed"));
93         fflush(stderr);
94         abort();
95         /* NOTREACHED */
96 }