summaryrefslogtreecommitdiff
path: root/src/debug.h
blob: 64626eb387e4d3f1c54b653ee5562efbeaec5c9e (plain)
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
/*
 * License: BSD-style license
 * Copyright: Radek Podgorny <radek@podgorny.cz>,
 *            Bernd Schubert <bernd.schubert@fastmail.fm
 */

#ifndef DEBUG_H
#define DEBUG_H

#include "opts.h"

extern FILE* dbgfile;

#define DBG_IN() DBG("\n");

#define DBG(format, ...) 						\
	do {								\
		if (!uopt.debug) break;					\
		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);						\
	} 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);


#endif // DEBUG_H