Expand PMF_FN_* macros.
[netbsd-mini2440.git] / dist / ntp / libisc / error.c
blob4124dd0988e6d7a8f59da522217e9b64992ddcea
1 /* $NetBSD$ */
3 /*
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 */
22 #include <config.h>
24 #include <stdio.h>
25 #include <stdlib.h>
27 #include <isc/error.h>
28 #include <isc/msgs.h>
30 static void
31 default_unexpected_callback(const char *, int, const char *, va_list)
32 ISC_FORMAT_PRINTF(3, 0);
34 static void
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;
41 void
42 isc_error_setunexpected(isc_errorcallback_t cb) {
43 if (cb == NULL)
44 unexpected_callback = default_unexpected_callback;
45 else
46 unexpected_callback = cb;
49 void
50 isc_error_setfatal(isc_errorcallback_t cb) {
51 if (cb == NULL)
52 fatal_callback = default_fatal_callback;
53 else
54 fatal_callback = cb;
57 void
58 isc_error_unexpected(const char *file, int line, const char *format, ...) {
59 va_list args;
61 va_start(args, format);
62 (unexpected_callback)(file, line, format, args);
63 va_end(args);
66 void
67 isc_error_fatal(const char *file, int line, const char *format, ...) {
68 va_list args;
70 va_start(args, format);
71 (fatal_callback)(file, line, format, args);
72 va_end(args);
73 abort();
76 void
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"));
83 static void
84 default_unexpected_callback(const char *file, int line, const char *format,
85 va_list args)
87 fprintf(stderr, "%s:%d: ", file, line);
88 vfprintf(stderr, format, args);
89 fprintf(stderr, "\n");
90 fflush(stderr);
93 static void
94 default_fatal_callback(const char *file, int line, const char *format,
95 va_list args)
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");
102 fflush(stderr);