]> wimlib.net Git - wimlib/blob - include/wimlib/error.h
resource.c: Cleanup and refactor
[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_attribute(printf, 2, 3);
16
17 extern int
18 wimlib_printf(const tchar *format, ...) _format_attribute(printf, 1, 2);
19 #endif /* !__WIN32__ */
20
21
22 static inline int
23 dummy_tprintf(const tchar *format, ...) _format_attribute(printf, 1, 2)
24 {
25         return 0;
26 }
27
28 #ifdef ENABLE_ERROR_MESSAGES
29 extern void
30 wimlib_error(const tchar *format, ...)
31         _format_attribute(printf, 1, 2) _cold_attribute;
32
33 extern void
34 wimlib_error_with_errno(const tchar *format, ...)
35                 _format_attribute(printf, 1, 2) _cold_attribute;
36
37 extern void
38 wimlib_warning(const tchar *format, ...)
39                 _format_attribute(printf, 1, 2) _cold_attribute;
40
41 extern void
42 wimlib_warning_with_errno(const tchar *format, ...)
43                 _format_attribute(printf, 1, 2) _cold_attribute;
44 #  define ERROR(format, ...)                    wimlib_error(T(format), ## __VA_ARGS__)
45 #  define ERROR_WITH_ERRNO(format, ...)         wimlib_error_with_errno(T(format), ## __VA_ARGS__)
46 #  define WARNING(format, ...)                  wimlib_warning(T(format), ## __VA_ARGS__)
47 #  define WARNING_WITH_ERRNO(format, ...)       wimlib_warning_with_errno(T(format), ## __VA_ARGS__)
48 extern bool wimlib_print_errors;
49 #else /* ENABLE_ERROR_MESSAGES */
50 #  define wimlib_print_errors 0
51 #  define ERROR(format, ...)                    dummy_tprintf(T(format), ## __VA_ARGS__)
52 #  define ERROR_WITH_ERRNO(format, ...)         dummy_tprintf(T(format), ## __VA_ARGS__)
53 #  define WARNING(format, ...)                  dummy_tprintf(T(format), ## __VA_ARGS__)
54 #  define WARNING_WITH_ERRNO(format, ...)       dummy_tprintf(T(format), ## __VA_ARGS__)
55 #endif /* !ENABLE_ERROR_MESSAGES */
56
57 #if defined(ENABLE_MORE_DEBUG) && !defined(ENABLE_DEBUG)
58 #  define ENABLE_DEBUG 1
59 #endif
60
61 #if defined(ENABLE_MORE_ASSERTIONS) && !defined(ENABLE_ASSERTIONS)
62 #  define ENABLE_ASSERTIONS 1
63 #endif
64
65
66 #ifdef ENABLE_DEBUG
67 extern void
68 wimlib_debug(const tchar *file, int line, const char *func,
69              const tchar *format, ...);
70 #  define DEBUG(format, ...) \
71                 wimlib_debug(T(__FILE__), __LINE__, __func__, T(format), ## __VA_ARGS__)
72
73 #else
74 #  define DEBUG(format, ...) dummy_tprintf(T(format), ## __VA_ARGS__)
75 #endif /* !ENABLE_DEBUG */
76
77 #ifdef ENABLE_MORE_DEBUG
78 #  define DEBUG2(format, ...) DEBUG(format, ## __VA_ARGS__)
79 #else
80 #  define DEBUG2(format, ...) dummy_tprintf(T(format), ## __VA_ARGS__)
81 #endif /* !ENABLE_MORE_DEBUG */
82
83 #endif /* _WIMLIB_ERROR_H */