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