4 * Copyright (C) 2004, 2005, 2007 Internet Systems Consortium, Inc. ("ISC")
5 * Copyright (C) 1998-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: error.c,v 1.21 2007/06/19 23:47:17 tbox Exp */
29 #include <isc/error.h>
32 /*% Default unexpected callback. */
34 default_unexpected_callback(const char *, int, const char *, va_list)
35 ISC_FORMAT_PRINTF(3, 0);
37 /*% Default fatal callback. */
39 default_fatal_callback(const char *, int, const char *, va_list)
40 ISC_FORMAT_PRINTF(3, 0);
42 /*% unexpected_callback */
43 static isc_errorcallback_t unexpected_callback
= default_unexpected_callback
;
44 static isc_errorcallback_t fatal_callback
= default_fatal_callback
;
47 isc_error_setunexpected(isc_errorcallback_t cb
) {
49 unexpected_callback
= default_unexpected_callback
;
51 unexpected_callback
= cb
;
55 isc_error_setfatal(isc_errorcallback_t cb
) {
57 fatal_callback
= default_fatal_callback
;
63 isc_error_unexpected(const char *file
, int line
, const char *format
, ...) {
66 va_start(args
, format
);
67 (unexpected_callback
)(file
, line
, format
, args
);
72 isc_error_fatal(const char *file
, int line
, const char *format
, ...) {
75 va_start(args
, format
);
76 (fatal_callback
)(file
, line
, format
, args
);
82 isc_error_runtimecheck(const char *file
, int line
, const char *expression
) {
83 isc_error_fatal(file
, line
, "RUNTIME_CHECK(%s) %s", expression
,
84 isc_msgcat_get(isc_msgcat
, ISC_MSGSET_GENERAL
,
85 ISC_MSG_FAILED
, "failed"));
89 default_unexpected_callback(const char *file
, int line
, const char *format
,
92 fprintf(stderr
, "%s:%d: ", file
, line
);
93 vfprintf(stderr
, format
, args
);
94 fprintf(stderr
, "\n");
99 default_fatal_callback(const char *file
, int line
, const char *format
,
102 fprintf(stderr
, "%s:%d: %s: ", file
, line
,
103 isc_msgcat_get(isc_msgcat
, ISC_MSGSET_GENERAL
,
104 ISC_MSG_FATALERROR
, "fatal error"));
105 vfprintf(stderr
, format
, args
);
106 fprintf(stderr
, "\n");