73 #if defined( MBG_TGT_NETWARE ) 75 #elif defined( MBG_TGT_OS2 ) 77 #elif defined( MBG_TGT_WIN32 ) 81 #elif defined( MBG_TGT_LINUX ) 82 #include <linux/module.h> 83 #include <linux/version.h> 84 #elif defined( MBG_TGT_FREEBSD ) 85 #include <sys/types.h> 86 #include <sys/systm.h> 87 #include <machine/stdarg.h> 88 #elif defined( MBG_TGT_NETBSD ) 89 #include <sys/param.h> 90 #if __NetBSD_Prereq__(7,0,0) // NetBSD >= 7.0 91 #include <sys/stdarg.h> 93 #include <machine/stdarg.h> 95 #elif defined( MBG_TGT_QNX ) 97 #elif defined( MBG_TGT_DOS ) 115 #if defined( _USE_PACK ) 116 #pragma pack( 1 ) // set byte alignment 117 #define _USING_BYTE_ALIGNMENT 124 #if !defined( DEBUG_MSG_SLEEP ) 125 #define DEBUG_MSG_SLEEP 0 129 _ext int debug_msg_sleep
137 #if defined( MBG_TGT_WIN32 ) 139 #define USE_MBG_KDD_MSG 1 141 #elif defined( MBG_TGT_LINUX ) 143 #define USE_MBG_KDD_MSG 1 145 #elif defined( MBG_TGT_FREEBSD ) 147 #if defined( _VA_LIST_DECLARED ) // at least since FreeBSD 8.2 149 #define USE_MBG_KDD_MSG 1 153 #define _printf printf 159 #elif defined( MBG_TGT_NETBSD ) 161 #if defined( __VA_LIST_DECLARED ) // at least NetBSD 7.1 163 #define USE_MBG_KDD_MSG 1 164 #define va_list __va_list 166 #elif defined( _BSD_VA_LIST_ ) 168 #define USE_MBG_KDD_MSG 1 172 #define _printf printf 178 #elif defined( MBG_TGT_NETWARE ) 180 #define _printf ConsolePrintf 184 #elif defined( MBG_TGT_OS2 ) 186 #define _printf iprintf 190 #elif defined( MBG_TGT_QNX ) // at least QNX 6.x (Neutrino) 192 #define USE_MBG_KDD_MSG 1 194 #elif defined( MBG_TGT_DOS ) 196 #define USE_MBG_KDD_MSG 1 198 #else // other targets ... 200 #if !defined( _printf ) 201 #define _printf printf 215 #if !defined( USE_MBG_KDD_MSG ) 216 #define USE_MBG_KDD_MSG 0 233 #define _mbg_kdd_msg_0( _lvl, _fmt ) \ 234 mbg_kdd_msg( _lvl, _fmt ) 236 #define _mbg_kdd_msg_1( _lvl, _fmt, _p1 ) \ 237 mbg_kdd_msg( _lvl, _fmt, (_p1) ) 239 #define _mbg_kdd_msg_2( _lvl, _fmt, _p1, _p2 ) \ 240 mbg_kdd_msg( _lvl, _fmt, (_p1), (_p2) ) 242 #define _mbg_kdd_msg_3( _lvl, _fmt, _p1, _p2, _p3 ) \ 243 mbg_kdd_msg( _lvl, _fmt, (_p1), (_p2), (_p3) ) 245 #define _mbg_kdd_msg_4( _lvl, _fmt, _p1, _p2, _p3, _p4 ) \ 246 mbg_kdd_msg( _lvl, _fmt, (_p1), (_p2), (_p3), (_p4) ) 248 #define _mbg_kdd_msg_5( _lvl, _fmt, _p1, _p2, _p3, _p4, _p5 ) \ 249 mbg_kdd_msg( _lvl, _fmt, (_p1), (_p2), (_p3), (_p4), (_p5) ) 251 #define _mbg_kdd_msg_6( _lvl, _fmt, _p1, _p2, _p3, _p4, _p5, _p6 ) \ 252 mbg_kdd_msg( _lvl, _fmt, (_p1), (_p2), (_p3), (_p4), (_p5), (_p6) ) 254 #define _mbg_kdd_msg_7( _lvl, _fmt, _p1, _p2, _p3, _p4, _p5, _p6, _p7 ) \ 255 mbg_kdd_msg( _lvl, _fmt, (_p1), (_p2), (_p3), (_p4), (_p5), (_p6), (_p7) ) 257 #define _mbg_kdd_msg_8( _lvl, _fmt, _p1, _p2, _p3, _p4, _p5, _p6, _p7, _p8 ) \ 258 mbg_kdd_msg( _lvl, _fmt, (_p1), (_p2), (_p3), (_p4), (_p5), (_p6), (_p7), (_p8) ) 262 #define _mbg_kdd_msg_0( _lvl, _fmt ) \ 264 _printf( _hd _fmt _tl ); \ 267 #define _mbg_kdd_msg_1( _lvl, _fmt, _p1 ) \ 269 _printf( _hd _fmt _tl, (_p1) ); \ 272 #define _mbg_kdd_msg_2( _lvl, _fmt, _p1, _p2 ) \ 274 _printf( _hd _fmt _tl, (_p1), (_p2) ); \ 277 #define _mbg_kdd_msg_3( _lvl, _fmt, _p1, _p2, _p3 ) \ 279 _printf( _hd _fmt _tl, (_p1), (_p2), (_p3) ); \ 282 #define _mbg_kdd_msg_4( _lvl, _fmt, _p1, _p2, _p3, _p4 ) \ 284 _printf( _hd _fmt _tl, (_p1), (_p2), (_p3), (_p4) ); \ 287 #define _mbg_kdd_msg_5( _lvl, _fmt, _p1, _p2, _p3, _p4, _p5 ) \ 289 _printf( _hd _fmt _tl, (_p1), (_p2), (_p3), (_p4), (_p5) ); \ 292 #define _mbg_kdd_msg_6( _lvl, _fmt, _p1, _p2, _p3, _p4, _p5, _p6 ) \ 294 _printf( _hd _fmt _tl, (_p1), (_p2), (_p3), (_p4), (_p5), (_p6) ); \ 297 #define _mbg_kdd_msg_7( _lvl, _fmt, _p1, _p2, _p3, _p4, _p5, _p6, _p7 ) \ 299 _printf( _hd _fmt _tl, (_p1), (_p2), (_p3), (_p4), (_p5), (_p6), (_p7) ); \ 302 #define _mbg_kdd_msg_8( _lvl, _fmt, _p1, _p2, _p3, _p4, _p5, _p6, _p7, _p8 ) \ 304 _printf( _hd _fmt _tl, (_p1), (_p2), (_p3), (_p4), (_p5), (_p6), (_p7), (_p8) ); \ 310 #if defined( DEBUG ) || defined( MBG_DEBUG ) || ( defined( DBG ) && DBG ) 312 #define _mbgddmsg_0( _f, _lvl, _fmt ) \ 315 { _mbg_kdd_msg_0( _lvl, _fmt ); } \ 318 #define _mbgddmsg_1( _f, _lvl, _fmt, _p1 ) \ 321 { _mbg_kdd_msg_1( _lvl, _fmt, (_p1) ); } \ 324 #define _mbgddmsg_2( _f, _lvl, _fmt, _p1, _p2 ) \ 327 { _mbg_kdd_msg_2( _lvl, _fmt, (_p1), (_p2) ); } \ 330 #define _mbgddmsg_3( _f, _lvl, _fmt, _p1, _p2, _p3 ) \ 333 { _mbg_kdd_msg_3( _lvl, _fmt, (_p1), (_p2), (_p3) ); } \ 336 #define _mbgddmsg_4( _f, _lvl, _fmt, _p1, _p2, _p3, _p4 ) \ 339 { _mbg_kdd_msg_4( _lvl, _fmt, (_p1), (_p2), (_p3), (_p4) ); } \ 342 #define _mbgddmsg_5( _f, _lvl, _fmt, _p1, _p2, _p3, _p4, _p5 ) \ 345 { _mbg_kdd_msg_5( _lvl, _fmt, (_p1), (_p2), (_p3), (_p4), (_p5) ); } \ 348 #define _mbgddmsg_6( _f, _lvl, _fmt, _p1, _p2, _p3, _p4, _p5, _p6 ) \ 351 { _mbg_kdd_msg_6( _lvl, _fmt, (_p1), (_p2), (_p3), (_p4), (_p5), (_p6) ); } \ 354 #define _mbgddmsg_7( _f, _lvl, _fmt, _p1, _p2, _p3, _p4, _p5, _p6, _p7 ) \ 357 { _mbg_kdd_msg_7( _f, _lvl, _fmt, (_p1), (_p2), (_p3), (_p4), (_p5), (_p6), (_p7) ); } \ 360 #define _mbgddmsg_8( _f, _lvl, _fmt, _p1, _p2, _p3, _p4, _p5, _p6, _p7, _p8 ) \ 363 { _mbg_kdd_msg_8( _lvl, _fmt, (_p1), (_p2), (_p3), (_p4), (_p5), (_p6), (_p7), (_p8) ); } \ 370 #define _mbgddmsg_0( _f, _lvl, _fmt ) _nop_macro_fnc() 371 #define _mbgddmsg_1( _f, _lvl, _fmt, _p1 ) _nop_macro_fnc() 372 #define _mbgddmsg_2( _f, _lvl, _fmt, _p1, _p2 ) _nop_macro_fnc() 373 #define _mbgddmsg_3( _f, _lvl, _fmt, _p1, _p2, _p3 ) _nop_macro_fnc() 374 #define _mbgddmsg_4( _f, _lvl, _fmt, _p1, _p2, _p3, _p4 ) _nop_macro_fnc() 375 #define _mbgddmsg_5( _f, _lvl, _fmt, _p1, _p2, _p3, _p4, _p5 ) _nop_macro_fnc() 376 #define _mbgddmsg_6( _f, _lvl, _fmt, _p1, _p2, _p3, _p4, _p5, _p6 ) _nop_macro_fnc() 377 #define _mbgddmsg_7( _f, _lvl, _fmt, _p1, _p2, _p3, _p4, _p5, _p6, _p7 ) _nop_macro_fnc() 378 #define _mbgddmsg_8( _f, _lvl, _fmt, _p1, _p2, _p3, _p4, _p5, _p6, _p7, _p8 ) _nop_macro_fnc() 384 #define MBG_LOG_FMT_ENTERING "Entering \"%s\"" 385 #define MBG_LOG_FMT_ENTERING_STR MBG_LOG_FMT_ENTERING " %s" 387 #define MBG_LOG_FMT_LEAVING "Leaving \"%s\"" 388 #define MBG_LOG_FMT_LEAVING_STR MBG_LOG_FMT_LEAVING " %s" 389 #define MBG_LOG_FMT_LEAVING_SUCCESS MBG_LOG_FMT_LEAVING " success" 390 #define MBG_LOG_FMT_LEAVING_ERR MBG_LOG_FMT_LEAVING " err" 391 #define MBG_LOG_FMT_LEAVING_ERR_MBG MBG_LOG_FMT_LEAVING " err %i: %s" 392 #define MBG_LOG_FMT_LEAVING_ERR_DEC MBG_LOG_FMT_LEAVING " err %li" 393 #define MBG_LOG_FMT_LEAVING_ERR_HEX MBG_LOG_FMT_LEAVING " err 0x%08lX" 397 #if USE_MBG_KDD_MSG && defined( DEBUG ) && DEBUG 399 #define _mbgddmsg_fnc_entry() \ 400 mbg_kdd_msg( MBG_LOG_DEBUG, MBG_LOG_FMT_ENTERING, \ 403 #define _mbgddmsg_fnc_entry_str( _s ) \ 404 mbg_kdd_msg( MBG_LOG_DEBUG, MBG_LOG_FMT_ENTERING_STR, \ 407 #define _mbgddmsg_fnc_exit() \ 408 mbg_kdd_msg( MBG_LOG_DEBUG, MBG_LOG_FMT_LEAVING, \ 411 #define _mbgddmsg_fnc_exit_str( _s ) \ 412 mbg_kdd_msg( MBG_LOG_DEBUG, MBG_LOG_FMT_LEAVING_STR, \ 415 #define _mbgddmsg_fnc_exit_success() \ 416 mbg_kdd_msg( MBG_LOG_DEBUG, MBG_LOG_FMT_LEAVING_SUCCESS, \ 419 #define _mbgddmsg_fnc_exit_err() \ 420 mbg_kdd_msg( MBG_LOG_ERR, MBG_LOG_FMT_LEAVING_ERR, \ 424 #define _mbgddmsg_fnc_exit_err_mbg( _mbg_errno ) \ 425 mbg_kdd_msg( MBG_LOG_ERR, MBG_LOG_FMT_LEAVING_ERR_MBG, \ 426 __func__, _mbg_errno, mbg_strerror( _mbg_errno ) ) 428 #define _mbgddmsg_fnc_exit_err_dec( _errnum ) \ 429 mbg_kdd_msg( MBG_LOG_ERR, MBG_LOG_FMT_LEAVING_ERR_DEC, \ 430 __func__, (long) (_errnum) ) 432 #define _mbgddmsg_fnc_exit_err_hex( _errnum ) \ 433 mbg_kdd_msg( MBG_LOG_ERR, MBG_LOG_FMT_LEAVING_ERR_HEX, \ 434 __func__, (ulong) (_errnum) ) 437 #define _mbgddmsg_fnc_exit_chk_mbg_rc( _rc ) \ 440 if ( mbg_rc_is_success( _rc ) ) \ 441 _mbgddmsg_fnc_exit_success(); \ 443 _mbgddmsg_fnc_exit_err_mbg( _rc ); \ 446 #define _mbgddmsg_fnc_exit_chk_rc( _rc ) \ 449 if ( mbg_rc_is_success( _rc ) ) \ 450 _mbgddmsg_fnc_exit_success(); \ 452 _mbgddmsg_fnc_exit_err_dec( _rc ); \ 455 #if defined( MBG_TGT_WIN32 ) 457 #define _mbgddmsg_fnc_exit_chk_st( _st ) \ 460 if ( NT_SUCCESS( (_st) ) ) \ 461 _mbgddmsg_fnc_exit_success(); \ 463 _mbgddmsg_fnc_exit_err_hex( _st ); \ 473 #define _mbgddmsg_fnc_entry() \ 474 _mbgddmsg_1( DEBUG, MBG_LOG_DEBUG, MBG_LOG_FMT_ENTERING, \ 477 #define _mbgddmsg_fnc_entry_str( _s ) \ 478 _mbgddmsg_2( DEBUG, MBG_LOG_DEBUG, MBG_LOG_FMT_ENTERING_STR, \ 481 #define _mbgddmsg_fnc_exit() \ 482 _mbgddmsg_1( DEBUG, MBG_LOG_DEBUG, MBG_LOG_FMT_LEAVING, \ 485 #define _mbgddmsg_fnc_exit_str( _s ) \ 486 _mbgddmsg_2( DEBUG, MBG_LOG_DEBUG, MBG_LOG_FMT_LEAVING_STR, \ 489 #define _mbgddmsg_fnc_exit_success() \ 490 _mbgddmsg_1( DEBUG, MBG_LOG_DEBUG, MBG_LOG_FMT_LEAVING_SUCCESS, \ 493 #define _mbgddmsg_fnc_exit_err() \ 494 _mbgddmsg_1( DEBUG, MBG_LOG_ERR, MBG_LOG_FMT_LEAVING_ERR_DEC, \ 497 #define _mbgddmsg_fnc_exit_err_mbg( _mbg_errno ) \ 498 _mbgddmsg_3( DEBUG, MBG_LOG_ERR, MBG_LOG_FMT_LEAVING_ERR_MBG, \ 499 __func__, _mbg_errno, mbg_strerror( _mbg_errno ) ) 501 #define _mbgddmsg_fnc_exit_err_dec( _errnum ) \ 502 _mbgddmsg_2( DEBUG, MBG_LOG_ERR, MBG_LOG_FMT_LEAVING_ERR_DEC, \ 503 __func__, (long) (_errnum) ) 505 #define _mbgddmsg_fnc_exit_err_hex( _errnum ) \ 506 _mbgddmsg_2( DEBUG, MBG_LOG_ERR, MBG_LOG_FMT_LEAVING_ERR_HEX, \ 507 __func__, (ulong) (_errnum) ) 509 #define _mbgddmsg_fnc_exit_chk_mbg_rc( _rc ) \ 510 _nop_macro_fnc() // TODO 512 #define _mbgddmsg_fnc_exit_chk_rc( _rc ) \ 513 _nop_macro_fnc() // TODO 515 #define _mbgddmsg_fnc_exit_chk_st( _st ) \ 516 _nop_macro_fnc() // TODO 525 __attribute__( ( format( printf, 3, 0 ) ) )
533 #if defined( MBG_TGT_WIN32 ) 535 n = _vsnprintf( s, max_len, fmt, args );
537 #elif defined( MBG_TGT_LINUX ) 539 n = vscnprintf( s, max_len, fmt, args );
541 #elif defined( MBG_TGT_BSD ) 543 n = vsnprintf( s, max_len, fmt, args );
545 #elif defined( MBG_TGT_QNX ) 549 #elif defined( MBG_TGT_DOS ) 553 #elif defined( MBG_TGT_NO_TGT ) 555 n = vsnprintf_no_tgt( s, max_len, fmt, args );
559 #error mbg_kdd_vsnprintf() needs to be implemented for this target. 568 #endif // USE_MBG_KDD_MSG 577 __attribute__( ( format( printf, 3, 4 ) ) )
int mbg_kdd_snprintf(
char *buf,
size_t size,
const char *fmt, ... ) ;
578 __attribute__( ( format( printf, 2, 3 ) ) )
void mbg_kdd_msg(
int lvl,
const char *fmt, ... ) ;
587 #if defined( _USING_BYTE_ALIGNMENT ) 588 #pragma pack() // set default alignment 589 #undef _USING_BYTE_ALIGNMENT
int mbg_kdd_snprintf(char *buf, size_t size, const char *fmt,...)
void mbg_kdd_msg(int lvl, const char *fmt,...)
int vsnprintf_safe(char *s, size_t max_len, const char *fmt, va_list args)
A portable, safe implementation of vsnprintf()
static __mbg_inline bool mbg_buffer_specs_valid(char *s, size_t max_len)
Check if the buffer plus size parameters passed to a function are valid.
static __mbg_inline int mbg_chk_snprint_results(size_t n, char *s, size_t max_len)
Check the results of an snprintf()-like function.
static __mbg_inline int mbg_kdd_vsnprintf(char *s, size_t max_len, const char *fmt, va_list args)