net-snmp  5.4.1
snmp_assert.h
00001 #ifndef SNMP_ASSERT_H
00002 #define SNMP_ASSERT_H
00003 
00004 #ifdef NETSNMP_USE_ASSERT
00005 #   include <assert.h>
00006 #else
00007 #   include <net-snmp/library/snmp_logging.h>
00008 #endif
00009 
00010 
00011 /*
00012  * MACROs don't need extern "C"
00013  */
00014 
00015 /*
00016  * define __STRING for systems (*cough* sun *cough*) that don't have it
00017  */
00018 #ifndef __STRING
00019 #  ifdef __STDC__
00020 #    define __STRING(x) #x
00021 #  else
00022 #    define __STRING(x) "x"
00023 #  endif /* __STDC__ */
00024 #endif /* __STRING */
00025 
00026 /*
00027  * always use assert if requested
00028  */
00029 #ifdef NETSNMP_USE_ASSERT
00030 /*   void netsnmp_assert( int );*/
00031 #   define netsnmp_assert(x)  assert( x )
00032 #else
00033 /*
00034  *  if asserts weren't requested, just log, unless NETSNMP_NO_DEBUGGING specified
00035  */
00036 #   ifndef NETSNMP_NO_DEBUGGING
00037 #      ifdef  HAVE_CPP_UNDERBAR_FUNCTION_DEFINED
00038 #         define netsnmp_assert(x)  do { \
00039                  if ( x ) \
00040                     ; \
00041                  else \
00042                     snmp_log(LOG_ERR,"netsnmp_assert %s failed %s:%d %s()\n", \
00043                              __STRING(x),__FILE__,__LINE__,__FUNCTION__); \
00044               }while(0)
00045 #      else
00046 #         define netsnmp_assert(x)  do { \
00047                  if( x )\
00048                     ; \
00049                  else \
00050                     snmp_log(LOG_ERR,"netsnmp_assert %s failed %s:%d\n", \
00051                              __STRING(x),__FILE__,__LINE__); \
00052               }while(0)
00053 #      endif
00054 #   else /* NO DEBUGGING */
00055 #      define netsnmp_assert(x)
00056 #   endif /* NO DEBUGGING */
00057 #endif /* not NETSNMP_USE_ASSERT */
00058 
00059 
00060 #endif /* SNMP_ASSERT_H */