No empty .Rs/.Re
[netbsd-mini2440.git] / external / bsd / libbind / dist / isc / assertions.c
blob4cfc72be887f2df0f488aeb7c6704e914a44c92b
1 /* $NetBSD$ */
3 /*
4 * Copyright (C) 2004, 2005, 2008 Internet Systems Consortium, Inc. ("ISC")
5 * Copyright (C) 1997, 1999, 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 #if !defined(LINT) && !defined(CODECENTER)
21 static const char rcsid[] = "Id: assertions.c,v 1.5 2008/11/14 02:36:51 marka Exp";
22 #endif
24 #include "port_before.h"
26 #include <errno.h>
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <string.h>
31 #include <isc/assertions.h>
33 #include "port_after.h"
36 * Forward.
39 static void default_assertion_failed(const char *, int, assertion_type,
40 const char *, int);
43 * Public.
46 assertion_failure_callback __assertion_failed = default_assertion_failed;
48 void
49 set_assertion_failure_callback(assertion_failure_callback f) {
50 if (f == NULL)
51 __assertion_failed = default_assertion_failed;
52 else
53 __assertion_failed = f;
56 const char *
57 assertion_type_to_text(assertion_type type) {
58 const char *result;
60 switch (type) {
61 case assert_require:
62 result = "REQUIRE";
63 break;
64 case assert_ensure:
65 result = "ENSURE";
66 break;
67 case assert_insist:
68 result = "INSIST";
69 break;
70 case assert_invariant:
71 result = "INVARIANT";
72 break;
73 default:
74 result = NULL;
76 return (result);
80 * Private.
83 /* coverity[+kill] */
84 static void
85 default_assertion_failed(const char *file, int line, assertion_type type,
86 const char *cond, int print_errno)
88 fprintf(stderr, "%s:%d: %s(%s)%s%s failed.\n",
89 file, line, assertion_type_to_text(type), cond,
90 (print_errno) ? ": " : "",
91 (print_errno) ? strerror(errno) : "");
92 abort();
93 /* NOTREACHED */
96 /*! \file */