Sync usage with man page.
[netbsd-mini2440.git] / external / bsd / ntp / dist / lib / isc / error.c
blob75c204d29776b1ceccba6d710f7dc33923ad9d29
1 /* $NetBSD$ */
3 /*
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 */
22 /*! \file */
24 #include <config.h>
26 #include <stdio.h>
27 #include <stdlib.h>
29 #include <isc/error.h>
30 #include <isc/msgs.h>
32 /*% Default unexpected callback. */
33 static void
34 default_unexpected_callback(const char *, int, const char *, va_list)
35 ISC_FORMAT_PRINTF(3, 0);
37 /*% Default fatal callback. */
38 static void
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;
46 void
47 isc_error_setunexpected(isc_errorcallback_t cb) {
48 if (cb == NULL)
49 unexpected_callback = default_unexpected_callback;
50 else
51 unexpected_callback = cb;
54 void
55 isc_error_setfatal(isc_errorcallback_t cb) {
56 if (cb == NULL)
57 fatal_callback = default_fatal_callback;
58 else
59 fatal_callback = cb;
62 void
63 isc_error_unexpected(const char *file, int line, const char *format, ...) {
64 va_list args;
66 va_start(args, format);
67 (unexpected_callback)(file, line, format, args);
68 va_end(args);
71 void
72 isc_error_fatal(const char *file, int line, const char *format, ...) {
73 va_list args;
75 va_start(args, format);
76 (fatal_callback)(file, line, format, args);
77 va_end(args);
78 abort();
81 void
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"));
88 static void
89 default_unexpected_callback(const char *file, int line, const char *format,
90 va_list args)
92 fprintf(stderr, "%s:%d: ", file, line);
93 vfprintf(stderr, format, args);
94 fprintf(stderr, "\n");
95 fflush(stderr);
98 static void
99 default_fatal_callback(const char *file, int line, const char *format,
100 va_list args)
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");
107 fflush(stderr);