]> wimlib.net Git - wimlib/blob - include/wimlib/error.h
7de749d3911a08e9abb5237567465de3a3ed1ff2
[wimlib] / include / wimlib / error.h
1 #ifndef _WIMLIB_ERROR_H
2 #define _WIMLIB_ERROR_H
3
4 #include "wimlib.h" /* Get error code definitions */
5 #include "wimlib/compiler.h"
6 #include "wimlib/types.h"
7
8 #include <stdio.h>
9
10 #ifdef __WIN32__
11 #  define wimlib_fprintf fwprintf
12 #  define wimlib_printf  wprintf
13 #else /* __WIN32__ */
14 extern int
15 wimlib_fprintf(FILE *fp, const tchar *format, ...) FORMAT(printf, 2, 3);
16
17 extern int
18 wimlib_printf(const tchar *format, ...) FORMAT(printf, 1, 2);
19 #endif /* !__WIN32__ */
20
21
22 static inline int dummy_tprintf(const tchar *format, ...)
23 {
24         return 0;
25 }
26
27 #ifdef ENABLE_ERROR_MESSAGES
28 extern void
29 wimlib_error(const tchar *format, ...) FORMAT(printf, 1, 2) COLD;
30
31 extern void
32 wimlib_error_with_errno(const tchar *format, ...) FORMAT(printf, 1, 2) COLD;
33
34 extern void
35 wimlib_warning(const tchar *format, ...) FORMAT(printf, 1, 2) COLD;
36
37 extern void
38 wimlib_warning_with_errno(const tchar *format, ...) FORMAT(printf, 1, 2) COLD;
39 #  define ERROR(format, ...)                    wimlib_error(T(format), ## __VA_ARGS__)
40 #  define ERROR_WITH_ERRNO(format, ...)         wimlib_error_with_errno(T(format), ## __VA_ARGS__)
41 #  define WARNING(format, ...)                  wimlib_warning(T(format), ## __VA_ARGS__)
42 #  define WARNING_WITH_ERRNO(format, ...)       wimlib_warning_with_errno(T(format), ## __VA_ARGS__)
43 #else /* ENABLE_ERROR_MESSAGES */
44 #  define ERROR(format, ...)                    dummy_tprintf(T(format), ## __VA_ARGS__)
45 #  define ERROR_WITH_ERRNO(format, ...)         dummy_tprintf(T(format), ## __VA_ARGS__)
46 #  define WARNING(format, ...)                  dummy_tprintf(T(format), ## __VA_ARGS__)
47 #  define WARNING_WITH_ERRNO(format, ...)       dummy_tprintf(T(format), ## __VA_ARGS__)
48 #endif /* !ENABLE_ERROR_MESSAGES */
49
50 #if defined(ENABLE_MORE_DEBUG) && !defined(ENABLE_DEBUG)
51 #  define ENABLE_DEBUG 1
52 #endif
53
54 #if defined(ENABLE_MORE_ASSERTIONS) && !defined(ENABLE_ASSERTIONS)
55 #  define ENABLE_ASSERTIONS 1
56 #endif
57
58 #ifdef ENABLE_DEBUG
59 extern void
60 wimlib_debug(const tchar *file, int line, const char *func,
61              const tchar *format, ...);
62 #  define DEBUG(format, ...) \
63                 wimlib_debug(T(__FILE__), __LINE__, __func__, T(format), ## __VA_ARGS__)
64
65 #else
66 #  define DEBUG(format, ...) dummy_tprintf(T(format), ## __VA_ARGS__)
67 #endif /* !ENABLE_DEBUG */
68
69 #ifdef ENABLE_MORE_DEBUG
70 #  define DEBUG2(format, ...) DEBUG(format, ## __VA_ARGS__)
71 #else
72 #  define DEBUG2(format, ...) dummy_tprintf(T(format), ## __VA_ARGS__)
73 #endif /* !ENABLE_MORE_DEBUG */
74
75 #endif /* _WIMLIB_ERROR_H */