debug.h

00001 /*
00002     libparted - a library for manipulating disk partitions
00003     Copyright (C) 1998, 1999, 2000, 2002 Free Software Foundation, Inc.
00004 
00005     This program is free software; you can redistribute it and/or modify
00006     it under the terms of the GNU General Public License as published by
00007     the Free Software Foundation; either version 2 of the License, or
00008     (at your option) any later version.
00009 
00010     This program is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013     GNU General Public License for more details.
00014 
00015     You should have received a copy of the GNU General Public License
00016     along with this program; if not, write to the Free Software
00017     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
00018 */
00019 
00020 #ifndef PED_DEBUG_H_INCLUDED
00021 #define PED_DEBUG_H_INCLUDED
00022 
00023 #include <config.h>
00024 
00025 #include <stdarg.h>
00026 
00027 #ifdef DEBUG
00028 
00029 typedef void (PedDebugHandler) ( const int level, const char* file, int line,
00030                                  const char* function, const char* msg );
00031 
00032 extern void ped_debug_set_handler (PedDebugHandler* handler);
00033 extern void ped_debug ( const int level, const char* file, int line,
00034                         const char* function, const char* msg, ... );
00035 
00036 extern int ped_assert ( int cond, const char* cond_text,
00037                         const char* file, int line, const char* function );
00038 
00039 #if defined(__GNUC__) && !defined(__JSFTRACE__)
00040 
00041 #define PED_DEBUG(level, ...) \
00042         ped_debug ( level, __FILE__, __LINE__, __PRETTY_FUNCTION__, \
00043                     __VA_ARGS__ );
00044 
00045 #define PED_ASSERT(cond, action)                                \
00046         do {                                                    \
00047         if (!ped_assert ( cond,                                 \
00048                           #cond,                                \
00049                           __FILE__,                             \
00050                           __LINE__,                             \
00051                           __PRETTY_FUNCTION__ ))                \
00052         {                                                       \
00053                 action;                                         \
00054         }                                                       \
00055         } while (0)
00056 
00057 #else /* !__GNUC__ */
00058 
00059 /* function because variadic macros are C99 */
00060 static void PED_DEBUG (int level, ...)
00061 {
00062         va_list         va_args;
00063         
00064         va_start (va_args, level);
00065         ped_debug ( level, "unknown file", 0, "unknown function", va_args );
00066         va_end (va_args);
00067 }
00068         
00069 #define PED_ASSERT(cond, action)                                \
00070         do {                                                    \
00071         if (!ped_assert ( cond,                                 \
00072                           #cond,                                \
00073                           "unknown",                            \
00074                           0,                                    \
00075                           "unknown" ))                          \
00076         {                                                       \
00077                 action;                                         \
00078         }                                                       \
00079         } while (0)
00080 
00081 #endif /* __GNUC__ */
00082 
00083 #else /* !DEBUG */
00084 
00085 #define PED_ASSERT(cond, action)        while (0) {}
00086 #define PED_DEBUG(level, ...)           while (0) {}
00087 
00088 
00089 #endif /* DEBUG */
00090 
00091 #endif /* PED_DEBUG_H_INCLUDED */
00092 

Generated on Fri May 4 05:15:31 2007 for libparted by  doxygen 1.5.2