From 760dee16d194b0248ee1d6e3b71e968bb774429c Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Mon, 20 May 2013 19:09:20 +0200 Subject: [PATCH] packagefs: Add va-args version ERRORV() to DebugSupport --- .../packagefs/util/DebugSupport.cpp | 29 ++++++++------ .../packagefs/util/DebugSupport.h | 38 +++++++++++-------- 2 files changed, 40 insertions(+), 27 deletions(-) diff --git a/src/add-ons/kernel/file_systems/packagefs/util/DebugSupport.cpp b/src/add-ons/kernel/file_systems/packagefs/util/DebugSupport.cpp index 8377cf340c..23f683e25e 100644 --- a/src/add-ons/kernel/file_systems/packagefs/util/DebugSupport.cpp +++ b/src/add-ons/kernel/file_systems/packagefs/util/DebugSupport.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2003-2009, Ingo Weinhold, ingo_weinhold@gmx.de. + * Copyright 2003-2013, Ingo Weinhold, ingo_weinhold@gmx.de. * Distributed under the terms of the MIT License. */ @@ -127,24 +127,29 @@ dbg_printf_end() #if DEBUG_PRINT + void -dbg_printf(const char *format,...) +dbg_vprintf(const char* format, va_list args) { if (!dbg_printf_lock()) return; + char buffer[1024]; - va_list args; - va_start(args, format); - // no vsnprintf() on PPC and in kernel - #if defined(__INTEL__) && USER - vsnprintf(buffer, sizeof(buffer) - 1, format, args); - #else - vsprintf(buffer, format, args); - #endif - va_end(args); - buffer[sizeof(buffer) - 1] = '\0'; + vsnprintf(buffer, sizeof(buffer) - 1, format, args); write(out, buffer, strlen(buffer)); + dbg_printf_unlock(); } + +void +dbg_printf(const char* format,...) +{ + va_list args; + va_start(args, format); + dbg_vprintf(format, args); + va_end(args); +} + + #endif // DEBUG_PRINT diff --git a/src/add-ons/kernel/file_systems/packagefs/util/DebugSupport.h b/src/add-ons/kernel/file_systems/packagefs/util/DebugSupport.h index 8e0dc49995..cb8ec3a1a5 100644 --- a/src/add-ons/kernel/file_systems/packagefs/util/DebugSupport.h +++ b/src/add-ons/kernel/file_systems/packagefs/util/DebugSupport.h @@ -44,16 +44,20 @@ # include # if DEBUG_PRINT # define __out dbg_printf +# define __outv dbg_vprintf # else # define __out printf +# define __outv vprintf # endif #else # include # include # if DEBUG_PRINT # define __out dbg_printf +# define __outv dbg_vprintf # else # define __out dprintf +# define __outv dvprintf # endif #endif @@ -74,18 +78,23 @@ status_t exit_debugging(); void dbg_printf_begin(); void dbg_printf_end(); #if DEBUG_PRINT - void dbg_printf(const char *format,...); + void dbg_vprintf(const char* format, va_list args); + void dbg_printf(const char* format,...); #else - static inline void dbg_printf(const char *,...) {} + static inline void dbg_vprintf(const char*, va_list) {} + static inline void dbg_printf(const char*,...) {} #endif -// Short overview over the debug output macros: +// Short overview of the debug output macros: // PRINT() -// is for general messages that very unlikely should appear in a release -// build +// general messages that shouldn't appear in a release build // FATAL() -// this is for fatal messages, when something has really gone wrong +// fatal messages, when something has really gone wrong +// ERROR() +// non-fatal error messages +// WARN() +// warning messages // INFORM() // general information, as disk size, etc. // REPORT_ERROR(status_t) @@ -121,7 +130,8 @@ void dbg_printf_end(); dbg_printf_end(); \ } -#define TPRINT(x...) DEBUG_CONTEXT( __out(x) ) +#define TPRINT(x...) DEBUG_CONTEXT( __out(x) ) +#define TPRINTV(format, args) DEBUG_CONTEXT( __outv(format, args) ) #define TREPORT_ERROR(status) \ DEBUG_CONTEXT_LINE( __out("%s\n", strerror(status)) ) #define TRETURN_ERROR(err) \ @@ -147,10 +157,6 @@ void dbg_printf_end(); #define REPORT_ERROR(status) TREPORT_ERROR(status) #define RETURN_ERROR(err) TRETURN_ERROR(err) #define SET_ERROR(var, err) TSET_ERROR(var, err) - #define FATAL(x...) DEBUG_CONTEXT( __out(x) ) - #define ERROR(x...) DEBUG_CONTEXT( __out(x) ) - #define WARN(x...) DEBUG_CONTEXT( __out(x) ) - #define INFORM(x...) DEBUG_CONTEXT( __out(x) ) #define FUNCTION(x...) TFUNCTION(x) #define FUNCTION_START() TFUNCTION_START() #define FUNCTION_END() TFUNCTION_END() @@ -161,10 +167,6 @@ void dbg_printf_end(); #define REPORT_ERROR(status) ; #define RETURN_ERROR(status) return status; #define SET_ERROR(var, err) var = err; - #define FATAL(x...) DEBUG_CONTEXT( __out(x) ) - #define ERROR(x...) DEBUG_CONTEXT( __out(x) ) - #define WARN(x...) DEBUG_CONTEXT( __out(x) ) - #define INFORM(x...) DEBUG_CONTEXT( __out(x) ) #define FUNCTION(x...) ; #define FUNCTION_START() ; #define FUNCTION_END() ; @@ -172,6 +174,12 @@ void dbg_printf_end(); #define D(x) ; #endif +#define FATAL(x...) TPRINT(x) +#define ERROR(x...) TPRINT(x) +#define ERRORV(format, args) TPRINTV(format, args) +#define WARN(x...) TPRINT(x) +#define INFORM(x...) TPRINT(x) + #ifndef TOUCH #define TOUCH(var) (void)var #endif