~ubuntu-branches/debian/squeeze/ntp/squeeze-201010051545

« back to all changes in this revision

Viewing changes to libisc/assertions.c

  • Committer: Bazaar Package Importer
  • Author(s): Matt Zimmerman
  • Date: 2004-10-11 16:10:27 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20041011161027-icyjbji8ujym633o
Tags: 1:4.2.0a-10ubuntu2
Use ntp.ubuntulinux.org instead of pool.ntp.org

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 1997-2001  Internet Software Consortium.
 
3
 *
 
4
 * Permission to use, copy, modify, and distribute this software for any
 
5
 * purpose with or without fee is hereby granted, provided that the above
 
6
 * copyright notice and this permission notice appear in all copies.
 
7
 *
 
8
 * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
 
9
 * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
 
10
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
 
11
 * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
 
12
 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
 
13
 * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
 
14
 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
 
15
 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 
16
 */
 
17
 
 
18
/* $Id: assertions.c,v 1.16 2001/07/16 03:52:05 mayer Exp $ */
 
19
 
 
20
#include <config.h>
 
21
 
 
22
#include <stdio.h>
 
23
#include <stdlib.h>
 
24
 
 
25
#include <isc/assertions.h>
 
26
#include <isc/msgs.h>
 
27
 
 
28
/*
 
29
 * Forward.
 
30
 */
 
31
 
 
32
static void
 
33
default_callback(const char *, int, isc_assertiontype_t, const char *);
 
34
 
 
35
/*
 
36
 * Public.
 
37
 */
 
38
 
 
39
LIBISC_EXTERNAL_DATA isc_assertioncallback_t isc_assertion_failed =
 
40
                                             default_callback;
 
41
 
 
42
void
 
43
isc_assertion_setcallback(isc_assertioncallback_t cb) {
 
44
        if (cb == NULL)
 
45
                isc_assertion_failed = default_callback;
 
46
        else
 
47
                isc_assertion_failed = cb;
 
48
}
 
49
 
 
50
const char *
 
51
isc_assertion_typetotext(isc_assertiontype_t type) {
 
52
        const char *result;
 
53
 
 
54
        /*
 
55
         * These strings have purposefully not been internationalized
 
56
         * because they are considered to essentially be keywords of
 
57
         * the ISC development environment.
 
58
         */
 
59
        switch (type) {
 
60
        case isc_assertiontype_require:
 
61
                result = "REQUIRE";
 
62
                break;
 
63
        case isc_assertiontype_ensure:
 
64
                result = "ENSURE";
 
65
                break;
 
66
        case isc_assertiontype_insist:
 
67
                result = "INSIST";
 
68
                break;
 
69
        case isc_assertiontype_invariant:
 
70
                result = "INVARIANT";
 
71
                break;
 
72
        default:
 
73
                result = NULL;
 
74
        }
 
75
        return (result);
 
76
}
 
77
 
 
78
/*
 
79
 * Private.
 
80
 */
 
81
 
 
82
static void
 
83
default_callback(const char *file, int line, isc_assertiontype_t type,
 
84
                 const char *cond)
 
85
{
 
86
        fprintf(stderr, "%s:%d: %s(%s) %s.\n",
 
87
                file, line, isc_assertion_typetotext(type), cond,
 
88
                isc_msgcat_get(isc_msgcat, ISC_MSGSET_GENERAL,
 
89
                               ISC_MSG_FAILED, "failed"));
 
90
        fflush(stderr);
 
91
        abort();
 
92
        /* NOTREACHED */
 
93
}