File:  [ELWIX - Embedded LightWeight unIX -] / embedaddon / ntp / lib / isc / assertions.c
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs - revision graph
Tue May 29 12:08:38 2012 UTC (12 years, 7 months ago) by misho
Branches: ntp, MAIN
CVS tags: v4_2_6p5p0, v4_2_6p5, HEAD
ntp 4.2.6p5

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

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>