Sync usage with man page.
[netbsd-mini2440.git] / dist / ntp / libisc / assertions.c
blob5aa29b481f87587d5f6829c346187e6af8d2e8c1
1 /* $NetBSD$ */
3 /*
4 * Copyright (C) 1997-2001 Internet Software Consortium.
6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
10 * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
11 * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
12 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
13 * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
14 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
15 * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
16 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
17 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20 /* Id: assertions.c,v 1.16 2001/07/16 03:52:05 mayer Exp */
22 #include <config.h>
24 #include <stdio.h>
25 #include <stdlib.h>
27 #include <isc/assertions.h>
28 #include <isc/msgs.h>
31 * Forward.
34 static void
35 default_callback(const char *, int, isc_assertiontype_t, const char *);
38 * Public.
41 LIBISC_EXTERNAL_DATA isc_assertioncallback_t isc_assertion_failed =
42 default_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;
52 const char *
53 isc_assertion_typetotext(isc_assertiontype_t type) {
54 const char *result;
57 * These strings have purposefully not been internationalized
58 * because they are considered to essentially be keywords of
59 * the ISC development environment.
61 switch (type) {
62 case isc_assertiontype_require:
63 result = "REQUIRE";
64 break;
65 case isc_assertiontype_ensure:
66 result = "ENSURE";
67 break;
68 case isc_assertiontype_insist:
69 result = "INSIST";
70 break;
71 case isc_assertiontype_invariant:
72 result = "INVARIANT";
73 break;
74 default:
75 result = NULL;
77 return (result);
81 * Private.
84 static void
85 default_callback(const char *file, int line, isc_assertiontype_t type,
86 const char *cond)
88 fprintf(stderr, "%s:%d: %s(%s) %s.\n",
89 file, line, isc_assertion_typetotext(type), cond,
90 isc_msgcat_get(isc_msgcat, ISC_MSGSET_GENERAL,
91 ISC_MSG_FAILED, "failed"));
92 fflush(stderr);
93 abort();
94 /* NOTREACHED */