Add BIND 9.2.4rc7.
[dragonfly.git] / contrib / bind-9.2.4rc7 / lib / isc / assertions.c
blob9fd451793a6116b8df395cdebfbe1d35ebec75fa
1 /*
2 * Copyright (C) 2004 Internet Systems Consortium, Inc. ("ISC")
3 * Copyright (C) 1997-2001 Internet Software Consortium.
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.
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.
18 /* $Id: assertions.c,v 1.16.2.1 2004/03/09 06:11:44 marka Exp $ */
20 #include <config.h>
22 #include <stdio.h>
23 #include <stdlib.h>
25 #include <isc/assertions.h>
26 #include <isc/msgs.h>
29 * Forward.
32 static void
33 default_callback(const char *, int, isc_assertiontype_t, const char *);
36 * Public.
39 LIBISC_EXTERNAL_DATA isc_assertioncallback_t isc_assertion_failed =
40 default_callback;
42 void
43 isc_assertion_setcallback(isc_assertioncallback_t cb) {
44 if (cb == NULL)
45 isc_assertion_failed = default_callback;
46 else
47 isc_assertion_failed = cb;
50 const char *
51 isc_assertion_typetotext(isc_assertiontype_t type) {
52 const char *result;
55 * These strings have purposefully not been internationalized
56 * because they are considered to essentially be keywords of
57 * the ISC development environment.
59 switch (type) {
60 case isc_assertiontype_require:
61 result = "REQUIRE";
62 break;
63 case isc_assertiontype_ensure:
64 result = "ENSURE";
65 break;
66 case isc_assertiontype_insist:
67 result = "INSIST";
68 break;
69 case isc_assertiontype_invariant:
70 result = "INVARIANT";
71 break;
72 default:
73 result = NULL;
75 return (result);
79 * Private.
82 static void
83 default_callback(const char *file, int line, isc_assertiontype_t type,
84 const char *cond)
86 fprintf(stderr, "%s:%d: %s(%s) %s.\n",
87 file, line, isc_assertion_typetotext(type), cond,
88 isc_msgcat_get(isc_msgcat, ISC_MSGSET_GENERAL,
89 ISC_MSG_FAILED, "failed"));
90 fflush(stderr);
91 abort();
92 /* NOTREACHED */