error_prints.h: add debug print macros

* defs.h (debug_flag): Move the declaration...
* error_prints.h (debug_flag): ... here.
(debug_msg, debug_perror_msg): New macro definitions.
Include <stdbool.h> for the debug_flag declaration.
This commit is contained in:
Eugene Syromiatnikov 2017-08-04 08:03:03 +02:00 committed by Dmitry V. Levin
parent 4f47c43ce7
commit 859bc3444c
2 changed files with 16 additions and 1 deletions

1
defs.h
View File

@ -355,7 +355,6 @@ typedef enum {
CFLAG_BOTH
} cflag_t;
extern cflag_t cflag;
extern bool debug_flag;
extern bool Tflag;
extern bool iflag;
extern bool count_wallclock;

View File

@ -33,8 +33,12 @@
#ifndef STRACE_ERROR_PRINTS_H
#define STRACE_ERROR_PRINTS_H
#include <stdbool.h>
#include "gcc_compat.h"
extern bool debug_flag;
void die(void) ATTRIBUTE_NORETURN;
void error_msg(const char *fmt, ...) ATTRIBUTE_FORMAT((printf, 1, 2));
@ -46,4 +50,16 @@ void error_msg_and_help(const char *fmt, ...)
void error_msg_and_die(const char *fmt, ...)
ATTRIBUTE_FORMAT((printf, 1, 2)) ATTRIBUTE_NORETURN;
/* Wrappers for if (debug_flag) error_msg(...) */
#define debug_msg(...) \
do { \
if (debug_flag) \
error_msg(__VA_ARGS__); \
} while (0)
#define debug_perror_msg(...) \
do { \
if (debug_flag) \
perror_msg(__VA_ARGS__); \
} while (0)
#endif /* !STRACE_ERROR_PRINTS_H */