4 * Copyright (C) 1998-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: error.c,v 1.16 2001/08/08 22:54:49 gson Exp */
27 #include <isc/error.h>
31 default_unexpected_callback(const char *, int, const char *, va_list)
32 ISC_FORMAT_PRINTF(3, 0);
35 default_fatal_callback(const char *, int, const char *, va_list)
36 ISC_FORMAT_PRINTF(3, 0);
38 static isc_errorcallback_t unexpected_callback
= default_unexpected_callback
;
39 static isc_errorcallback_t fatal_callback
= default_fatal_callback
;
42 isc_error_setunexpected(isc_errorcallback_t cb
) {
44 unexpected_callback
= default_unexpected_callback
;
46 unexpected_callback
= cb
;
50 isc_error_setfatal(isc_errorcallback_t cb
) {
52 fatal_callback
= default_fatal_callback
;
58 isc_error_unexpected(const char *file
, int line
, const char *format
, ...) {
61 va_start(args
, format
);
62 (unexpected_callback
)(file
, line
, format
, args
);
67 isc_error_fatal(const char *file
, int line
, const char *format
, ...) {
70 va_start(args
, format
);
71 (fatal_callback
)(file
, line
, format
, args
);
77 isc_error_runtimecheck(const char *file
, int line
, const char *expression
) {
78 isc_error_fatal(file
, line
, "RUNTIME_CHECK(%s) %s", expression
,
79 isc_msgcat_get(isc_msgcat
, ISC_MSGSET_GENERAL
,
80 ISC_MSG_FAILED
, "failed"));
84 default_unexpected_callback(const char *file
, int line
, const char *format
,
87 fprintf(stderr
, "%s:%d: ", file
, line
);
88 vfprintf(stderr
, format
, args
);
89 fprintf(stderr
, "\n");
94 default_fatal_callback(const char *file
, int line
, const char *format
,
97 fprintf(stderr
, "%s:%d: %s: ", file
, line
,
98 isc_msgcat_get(isc_msgcat
, ISC_MSGSET_GENERAL
,
99 ISC_MSG_FATALERROR
, "fatal error"));
100 vfprintf(stderr
, format
, args
);
101 fprintf(stderr
, "\n");