1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
/*
* License: BSD-style license
* Copyright: Radek Podgorny <radek@podgorny.cz>,
* Bernd Schubert <bernd.schubert@fastmail.fm
*/
#ifndef DEBUG_H
#define DEBUG_H
#include <errno.h>
#include "opts.h"
#define DBG_IN() DBG("\n");
#define DBG(format, ...) \
do { \
if (!uopt.debug) break; \
int _errno = errno; \
FILE* dbgfile = get_dbgfile(); \
fprintf(stderr, "%s(): %d: ", __func__, __LINE__); \
fprintf(dbgfile, "%s(): %d: ", __func__, __LINE__); \
fprintf(stderr, format, ##__VA_ARGS__); \
fprintf(dbgfile, format, ##__VA_ARGS__); \
fflush(stderr); \
fflush(stdout); \
put_dbgfile(); \
errno = _errno; \
} while (0)
#define RETURN(returncode) \
do { \
if (uopt.debug) DBG("return %d\n", returncode); \
return returncode; \
} while (0)
/* In order to prevent useless function calls and to make the compiler
* to optimize those out, debug.c will only have definitions if DEBUG
* is defined. So if DEBUG is NOT defined, we define empty functions here */
int debug_init();
void dbg_in(const char *function);
FILE* get_dbgfile(void);
void put_dbgfile(void);
#endif // DEBUG_H
|