]>
Commit | Line | Data |
---|---|---|
37be9888 | 1 | /* |
4ac4a490 | 2 | * Copyright (C) 1996-2017 The Squid Software Foundation and contributors |
37be9888 AJ |
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 | ||
c19c2c0b AJ |
9 | #ifndef COMPAT_DEBUG_H |
10 | #define COMPAT_DEBUG_H | |
fdbb3b19 AJ |
11 | |
12 | /* | |
c19c2c0b | 13 | * A debug method for use of external helpers and tools. |
fdbb3b19 | 14 | * It shunts the debug messages down stderr for logging by Squid |
c19c2c0b | 15 | * or display to the user instead of corrupting the stdout data stream. |
fdbb3b19 | 16 | */ |
fdbb3b19 AJ |
17 | #if HAVE_UNISTD_H |
18 | #include <unistd.h> | |
19 | #endif | |
20 | ||
21 | /* Debugging stuff */ | |
22 | ||
2a9c817f FC |
23 | SQUIDCEXTERN int debug_enabled; |
24 | ||
fdbb3b19 | 25 | /* the macro overload style is really a gcc-ism */ |
a45f2153 | 26 | #if defined(__GNUC__) || defined(__SUNPRO_CC) |
fdbb3b19 | 27 | |
c19c2c0b | 28 | #define debug(X...) \ |
fdbb3b19 | 29 | if (debug_enabled) { \ |
2266451a | 30 | fprintf(stderr, "%s(%d): pid=%ld :", __FILE__, __LINE__, static_cast<long>(getpid())); \ |
fdbb3b19 | 31 | fprintf(stderr,X); \ |
3c999603 | 32 | } else (void)0 |
fdbb3b19 | 33 | |
900809ea FC |
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 | ||
a45f2153 | 40 | #else /* __GNUC__ || __SUNPRO_CC */ |
fdbb3b19 | 41 | |
2a9c817f | 42 | /* non-GCC compilers can't do the above macro define yet. */ |
21737d17 | 43 | void debug(const char *format,...); |
fdbb3b19 AJ |
44 | #endif |
45 | ||
c19c2c0b | 46 | #endif /* COMPAT_DEBUG_H */ |
f53969cc | 47 |