http://linux-ntfs.sourceforge.net/snapshots/ntfsprogs-200307311516.tar.bz2
[ntfsprogs.git] / include / debug.h
1 /*
2  * debug.h - Debugging output functions. Part of the Linux-NTFS project.
3  *
4  * Copyright (c) 2002 Anton Altaparmakov
5  *
6  * This program/include file is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License as published
8  * by the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program/include file is distributed in the hope that it will be
12  * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
13  * of 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 (in the main directory of the Linux-NTFS
18  * distribution in the file COPYING); if not, write to the Free Software
19  * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20  */
21
22 #ifndef _NTFS_DEBUG_H
23 #define _NTFS_DEBUG_H
24
25 #include "config.h"
26
27 #ifdef HAVE_STDIO_H
28 #       include <stdio.h>
29 #endif
30
31 #include "attrib.h"
32
33 #ifdef DEBUG
34
35 #ifdef HAVE_STDARG_H
36 #       include <stdarg.h>
37 #endif
38 #include <errno.h>
39
40 /* Debug output to stderr. To get it run ./configure --enable-debug. */
41
42 static __inline__ void Dprintf(const char *fmt, ...)
43 {
44         int eo = errno;
45         va_list ap;
46
47         va_start(ap, fmt);
48         vfprintf(stderr, fmt, ap);
49         va_end(ap);
50         errno = eo;
51 }
52
53 static __inline__ void Dputs(const char *s)
54 {
55         int eo = errno;
56         fprintf(stderr, "%s\n", s);
57         errno = eo;
58 }
59
60 static __inline__ void Dperror(const char *s)
61 {
62         int eo = errno;
63         perror(s);
64         errno = eo;
65 }
66
67 extern void ntfs_debug_runlist_dump(const runlist_element *rl);
68
69 #else /* if !DEBUG */
70
71 static __inline__ void Dprintf(const char *fmt, ...) {}
72 static __inline__ void Dputs(const char *s) {}
73 static __inline__ void Dperror(const char *s) {}
74 static __inline__ void ntfs_debug_runlist_dump(const runlist_element *rl) {}
75
76 #endif /* !DEBUG */
77
78 #define NTFS_BUG(msg)                                                     \
79 {                                                                         \
80         int ___i;                                                         \
81         fprintf(stderr, "libntfs: Bug in %s(): %s\n", __FUNCTION__, msg); \
82         Dputs("Forcing segmentation fault!");                             \
83         ___i = ((int*)NULL)[1];                                           \
84 }
85
86 #endif /* defined _NTFS_DEBUG_H */
87