badmagic.c

Go to the documentation of this file.
00001 /*                      B A D M A G I C . C
00002  * BRL-CAD
00003  *
00004  * Copyright (c) 2004-2006 United States Government as represented by
00005  * the U.S. Army Research Laboratory.
00006  *
00007  * This library is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public License
00009  * as published by the Free Software Foundation; either version 2 of
00010  * the License, or (at your option) any later version.
00011  *
00012  * This library is distributed in the hope that it will be useful, but
00013  * WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Library General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with this file; see the file named COPYING for more
00019  * information.
00020  */
00021 
00022 /** \addtogroup magic */
00023 /*@{*/
00024 /** @file badmagic.c
00025  *
00026  * @brief
00027  * Routines to check magic numbers
00028  *
00029  *  Routines involved with handling "magic numbers" used to identify
00030  *  various in-memory data structures.
00031  *
00032  *  @author Lee A. Butler
00033  *  @author Michael John Muuss
00034  *
00035  *  @par Source -
00036  *      The U. S. Army Research Laboratory                      @n
00037  *      Aberdeen Proving Ground, Maryland  21005-5068  USA
00038  */
00039 
00040 #ifndef lint
00041 static const char RCSbadmagic[] = "@(#)$Header: /cvsroot/brlcad/brlcad/src/libbu/badmagic.c,v 14.11 2006/09/03 15:14:07 lbutler Exp $ (ARL)";
00042 #endif
00043 
00044 #include "common.h"
00045 
00046 
00047 
00048 #include <stdio.h>
00049 #include "machine.h"
00050 #include "bu.h"
00051 
00052 /**
00053  *                      B U _ B A D M A G I C
00054  *@brief
00055  *  Support routine for BU_CKMAG macro
00056  */
00057 void
00058 bu_badmagic(const long int *ptr, unsigned long int magic, const char *str, const char *file, int line)
00059 {
00060         char    buf[512];
00061 
00062         if( !(ptr) )  {
00063                 sprintf(buf, "ERROR: NULL %s pointer, file %s, line %d\n",
00064                         str, file, line );
00065                 bu_bomb(buf);
00066         }
00067         if( ((size_t)(ptr)) & (sizeof(long)-1) )  {
00068                 sprintf(buf, "ERROR: x%lx mis-aligned %s pointer, file %s, line %d\n",
00069                         (long)ptr, str, file, line );
00070                 bu_bomb(buf);
00071         }
00072         if( *(ptr) != (long int)(magic) )  {
00073                 sprintf(buf, "ERROR: bad pointer x%lx: s/b %s(x%lx), was %s(x%lx), file %s, line %d\n",
00074                         (long)ptr,
00075                         str, magic,
00076                         bu_identify_magic( *(ptr) ), *(ptr),
00077                         file, line );
00078                 bu_bomb(buf);
00079         }
00080 }
00081 /*@}*/
00082 /*
00083  * Local Variables:
00084  * mode: C
00085  * tab-width: 8
00086  * c-basic-offset: 4
00087  * indent-tabs-mode: t
00088  * End:
00089  * ex: shiftwidth=4 tabstop=8
00090  */

Generated on Mon Sep 18 01:24:47 2006 for BRL-CAD by  doxygen 1.4.6