~youscribe/parted/3.1

« back to all changes in this revision

Viewing changes to include/parted/debug.h

  • Committer: Guilhem Lettron
  • Date: 2012-10-22 14:37:59 UTC
  • Revision ID: guilhem+ubuntu@lettron.fr-20121022143759-m403kecgz13sknvp
3.1 from tarball

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    libparted - a library for manipulating disk partitions
 
3
    Copyright (C) 1998-2000, 2002, 2007, 2009-2012 Free Software Foundation,
 
4
    Inc.
 
5
 
 
6
    This program is free software; you can redistribute it and/or modify
 
7
    it under the terms of the GNU General Public License as published by
 
8
    the Free Software Foundation; either version 3 of the License, or
 
9
    (at your option) any later version.
 
10
 
 
11
    This program is distributed in the hope that it will be useful,
 
12
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
    GNU General Public License for more details.
 
15
 
 
16
    You should have received a copy of the GNU General Public License
 
17
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
18
*/
 
19
 
 
20
#ifndef PED_DEBUG_H_INCLUDED
 
21
#define PED_DEBUG_H_INCLUDED
 
22
 
 
23
#include <stdarg.h>
 
24
 
 
25
#ifdef DEBUG
 
26
 
 
27
typedef void (PedDebugHandler) ( const int level, const char* file, int line,
 
28
                                 const char* function, const char* msg );
 
29
 
 
30
extern void ped_debug_set_handler (PedDebugHandler* handler);
 
31
extern void ped_debug ( const int level, const char* file, int line,
 
32
                        const char* function, const char* msg, ... );
 
33
 
 
34
extern void __attribute__((__noreturn__))
 
35
ped_assert ( const char* cond_text,
 
36
                         const char* file, int line, const char* function );
 
37
 
 
38
#if defined __GNUC__ && !defined __JSFTRACE__
 
39
 
 
40
#define PED_DEBUG(level, ...) \
 
41
        ped_debug ( level, __FILE__, __LINE__, __PRETTY_FUNCTION__, \
 
42
                    __VA_ARGS__ )
 
43
 
 
44
#define PED_ASSERT(cond)                                        \
 
45
        do {                                                    \
 
46
                if (!(cond)) {                                  \
 
47
                        ped_assert (                            \
 
48
                          #cond,                                \
 
49
                          __FILE__,                             \
 
50
                          __LINE__,                             \
 
51
                          __PRETTY_FUNCTION__ );                \
 
52
                }                                               \
 
53
        } while (0)
 
54
 
 
55
#else /* !__GNUC__ */
 
56
 
 
57
/* function because variadic macros are C99 */
 
58
static void PED_DEBUG (int level, ...)
 
59
{
 
60
        va_list         va_args;
 
61
 
 
62
        va_start (va_args, level);
 
63
        ped_debug ( level, "unknown file", 0, "unknown function", va_args );
 
64
        va_end (va_args);
 
65
}
 
66
 
 
67
#define PED_ASSERT(cond)                                        \
 
68
        do {                                                    \
 
69
                if (!(cond)) {                                  \
 
70
                        ped_assert (                            \
 
71
                          #cond,                                \
 
72
                          "unknown",                            \
 
73
                          0,                                    \
 
74
                          "unknown");                           \
 
75
                }                                               \
 
76
        } while (0)
 
77
 
 
78
#endif /* __GNUC__ */
 
79
 
 
80
#else /* !DEBUG */
 
81
 
 
82
#define PED_ASSERT(cond)                do {} while (0)
 
83
#define PED_DEBUG(level, ...)           do {} while (0)
 
84
 
 
85
 
 
86
#endif /* DEBUG */
 
87
 
 
88
#endif /* PED_DEBUG_H_INCLUDED */