@@ -19,9 +19,6 @@
#include "common/messages.h"
#include "common/utils.h"
-#define PREFIX_ERROR "ERROR: "
-#define PREFIX_WARNING "WARNING: "
-
static const char *common_error_string[] = {
[ERROR_MSG_MEMORY] = "not enough memory",
[ERROR_MSG_START_TRANS] = "failed to start transaction",
@@ -29,40 +26,13 @@ static const char *common_error_string[] = {
};
__attribute__ ((format (printf, 1, 2)))
-void __btrfs_warning(const char *fmt, ...)
-{
- va_list args;
-
- fputs(PREFIX_WARNING, stderr);
- va_start(args, fmt);
- vfprintf(stderr, fmt, args);
- va_end(args);
- fputc('\n', stderr);
-}
-
-__attribute__ ((format (printf, 1, 2)))
-void __btrfs_error(const char *fmt, ...)
+void __btrfs_printf(const char *fmt, ...)
{
va_list args;
- fputs(PREFIX_ERROR, stderr);
va_start(args, fmt);
vfprintf(stderr, fmt, args);
va_end(args);
- fputc('\n', stderr);
-}
-
-__attribute__ ((format (printf, 1, 2)))
-void internal_error(const char *fmt, ...)
-{
- va_list vargs;
-
- va_start(vargs, fmt);
- fputs("INTERNAL " PREFIX_ERROR, stderr);
- vfprintf(stderr, fmt, vargs);
- va_end(vargs);
- fputc('\n', stderr);
- print_trace();
}
static bool should_print(int level)
@@ -40,6 +40,28 @@
#define DO_ABORT_ON_ERROR do { } while (0)
#endif
+#define PREFIX_ERROR "ERROR: "
+#define PREFIX_WARNING "WARNING: "
+
+#define __btrfs_msg(prefix, fmt, ...) \
+ do { \
+ fputs((prefix), stderr); \
+ __btrfs_printf((fmt), ##__VA_ARGS__); \
+ fputc('\n', stderr); \
+ } while (0)
+
+#define __btrfs_warning(fmt, ...) \
+ __btrfs_msg(PREFIX_WARNING, fmt, ##__VA_ARGS__)
+
+#define __btrfs_error(fmt, ...) \
+ __btrfs_msg(PREFIX_ERROR, fmt, ##__VA_ARGS__)
+
+#define internal_error(fmt, ...) \
+ do { \
+ __btrfs_msg("INTERNAL " PREFIX_ERROR, fmt, ##__VA_ARGS__); \
+ print_trace(); \
+ } while (0)
+
#define error(fmt, ...) \
do { \
PRINT_TRACE_ON_ERROR; \
@@ -87,13 +109,7 @@
} while (0)
__attribute__ ((format (printf, 1, 2)))
-void __btrfs_warning(const char *fmt, ...);
-
-__attribute__ ((format (printf, 1, 2)))
-void __btrfs_error(const char *fmt, ...);
-
-__attribute__ ((format (printf, 1, 2)))
-void internal_error(const char *fmt, ...);
+void __btrfs_printf(const char *fmt, ...);
/*
* Level of messages that must be printed by default (in case the verbosity
These helpers all do variations on the same thing, so add a helper to just do the printf part, and a macro to handle the special prefix and postfix, and then make the helpers just use the macro and new helper. Signed-off-by: Josef Bacik <josef@toxicpanda.com> --- common/messages.c | 32 +------------------------------- common/messages.h | 30 +++++++++++++++++++++++------- 2 files changed, 24 insertions(+), 38 deletions(-)