]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * Copyright (C) 1996-2018 The Squid Software Foundation and contributors | |
3 | * | |
4 | * Squid software is distributed under GPLv2+ license and includes | |
5 | * contributions from numerous individuals and organizations. | |
6 | * Please see the COPYING and CONTRIBUTORS files for details. | |
7 | */ | |
8 | ||
9 | #ifndef COMPAT_DEBUG_H | |
10 | #define COMPAT_DEBUG_H | |
11 | ||
12 | /* | |
13 | * A debug method for use of external helpers and tools. | |
14 | * It shunts the debug messages down stderr for logging by Squid | |
15 | * or display to the user instead of corrupting the stdout data stream. | |
16 | */ | |
17 | #if HAVE_UNISTD_H | |
18 | #include <unistd.h> | |
19 | #endif | |
20 | ||
21 | /* Debugging stuff */ | |
22 | ||
23 | SQUIDCEXTERN int debug_enabled; | |
24 | ||
25 | /* the macro overload style is really a gcc-ism */ | |
26 | #if defined(__GNUC__) || defined(__SUNPRO_CC) | |
27 | ||
28 | #define debug(X...) \ | |
29 | if (debug_enabled) { \ | |
30 | fprintf(stderr, "%s(%d): pid=%ld :", __FILE__, __LINE__, static_cast<long>(getpid())); \ | |
31 | fprintf(stderr,X); \ | |
32 | } else (void)0 | |
33 | ||
34 | #define ndebug(content) ndebug_(__FILE__, __LINE__, content) | |
35 | #define ndebug_(file, line, content) if (debug_enabled) { \ | |
36 | std::cerr << file << '(' << line << ')' << ": pid=" << getpid() << ':' \ | |
37 | << content << std::endl; \ | |
38 | } else (void)0 | |
39 | ||
40 | #else /* __GNUC__ || __SUNPRO_CC */ | |
41 | ||
42 | /* non-GCC compilers can't do the above macro define yet. */ | |
43 | void debug(const char *format,...); | |
44 | #endif | |
45 | ||
46 | #endif /* COMPAT_DEBUG_H */ | |
47 |