]> wimlib.net Git - wimlib/blob - include/wimlib/error.h
Remove printf extension
[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 static inline int _format_attribute(printf, 1, 2)
11 dummy_tprintf(const tchar *format, ...)
12 {
13         return 0;
14 }
15
16 #ifdef ENABLE_ERROR_MESSAGES
17 extern void
18 wimlib_error(const tchar *format, ...)
19         _format_attribute(printf, 1, 2) _cold_attribute;
20
21 extern void
22 wimlib_error_with_errno(const tchar *format, ...)
23                 _format_attribute(printf, 1, 2) _cold_attribute;
24
25 extern void
26 wimlib_warning(const tchar *format, ...)
27                 _format_attribute(printf, 1, 2) _cold_attribute;
28
29 extern void
30 wimlib_warning_with_errno(const tchar *format, ...)
31                 _format_attribute(printf, 1, 2) _cold_attribute;
32 #  define ERROR(format, ...)                    wimlib_error(T(format), ## __VA_ARGS__)
33 #  define ERROR_WITH_ERRNO(format, ...)         wimlib_error_with_errno(T(format), ## __VA_ARGS__)
34 #  define WARNING(format, ...)                  wimlib_warning(T(format), ## __VA_ARGS__)
35 #  define WARNING_WITH_ERRNO(format, ...)       wimlib_warning_with_errno(T(format), ## __VA_ARGS__)
36 extern bool wimlib_print_errors;
37 #else /* ENABLE_ERROR_MESSAGES */
38 #  define wimlib_print_errors 0
39 #  define ERROR(format, ...)                    dummy_tprintf(T(format), ## __VA_ARGS__)
40 #  define ERROR_WITH_ERRNO(format, ...)         dummy_tprintf(T(format), ## __VA_ARGS__)
41 #  define WARNING(format, ...)                  dummy_tprintf(T(format), ## __VA_ARGS__)
42 #  define WARNING_WITH_ERRNO(format, ...)       dummy_tprintf(T(format), ## __VA_ARGS__)
43 #endif /* !ENABLE_ERROR_MESSAGES */
44
45 #if defined(ENABLE_MORE_DEBUG) && !defined(ENABLE_DEBUG)
46 #  define ENABLE_DEBUG 1
47 #endif
48
49 #if defined(ENABLE_MORE_ASSERTIONS) && !defined(ENABLE_ASSERTIONS)
50 #  define ENABLE_ASSERTIONS 1
51 #endif
52
53
54 #ifdef ENABLE_DEBUG
55 extern void
56 wimlib_debug(const tchar *file, int line, const char *func,
57              const tchar *format, ...);
58 #  define DEBUG(format, ...) \
59                 wimlib_debug(T(__FILE__), __LINE__, __func__, T(format), ## __VA_ARGS__)
60
61 #else
62 #  define DEBUG(format, ...) dummy_tprintf(T(format), ## __VA_ARGS__)
63 #endif /* !ENABLE_DEBUG */
64
65 #endif /* _WIMLIB_ERROR_H */