summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLorenzo Colitti <lorenzo@google.com>2015-01-27 04:02:42 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2015-01-27 04:02:42 +0000
commitf2d02c38fb7a7b91ddbb7e54fffa1e9c6c0c7449 (patch)
tree977b097721d87b1138153ad99503057fbcb9cc14
parent5d428bbab4d5a1124186a75bef6a4fb008682e43 (diff)
parent616344d169542aa0549ab19b0ed931e14014907f (diff)
downloadbionic-f2d02c38fb7a7b91ddbb7e54fffa1e9c6c0c7449.zip
bionic-f2d02c38fb7a7b91ddbb7e54fffa1e9c6c0c7449.tar.gz
bionic-f2d02c38fb7a7b91ddbb7e54fffa1e9c6c0c7449.tar.bz2
Merge "Make bionic compile even if resolver debugging is enabled."
-rw-r--r--libc/dns/resolv/res_cache.c57
1 files changed, 33 insertions, 24 deletions
diff --git a/libc/dns/resolv/res_cache.c b/libc/dns/resolv/res_cache.c
index c431835..573fcbe 100644
--- a/libc/dns/resolv/res_cache.c
+++ b/libc/dns/resolv/res_cache.c
@@ -28,6 +28,8 @@
#include "resolv_cache.h"
#include <resolv.h>
+#include <stdarg.h>
+#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
@@ -45,6 +47,8 @@
#include "resolv_netid.h"
#include "res_private.h"
+#include "private/libc_logging.h"
+
/* This code implements a small and *simple* DNS resolver cache.
*
* It is only used to cache DNS answers for a time defined by the smallest TTL
@@ -152,13 +156,21 @@
/* set to 1 to debug query data */
#define DEBUG_DATA 0
-#undef XLOG
#if DEBUG
-# include "private/libc_logging.h"
-# define XLOG(...) __libc_format_log(ANDROID_LOG_DEBUG,"libc",__VA_ARGS__)
+#define __DEBUG__
+#else
+#define __DEBUG__ __attribute__((unused))
+#endif
-#include <stdio.h>
-#include <stdarg.h>
+#undef XLOG
+
+#define XLOG(...) ({ \
+ if (DEBUG) { \
+ __libc_format_log(ANDROID_LOG_DEBUG,"libc",__VA_ARGS__); \
+ } else { \
+ ((void)0); \
+ } \
+})
/** BOUNDED BUFFER FORMATTING
**/
@@ -205,7 +217,7 @@
*/
/* add a char to a bounded buffer */
-static char*
+char*
_bprint_c( char* p, char* end, int c )
{
if (p < end) {
@@ -220,7 +232,7 @@ _bprint_c( char* p, char* end, int c )
}
/* add a sequence of bytes to a bounded buffer */
-static char*
+char*
_bprint_b( char* p, char* end, const char* buf, int len )
{
int avail = end - p;
@@ -243,15 +255,15 @@ _bprint_b( char* p, char* end, const char* buf, int len )
}
/* add a string to a bounded buffer */
-static char*
+char*
_bprint_s( char* p, char* end, const char* str )
{
return _bprint_b(p, end, str, strlen(str));
}
/* add a formatted string to a bounded buffer */
-static char*
-_bprint( char* p, char* end, const char* format, ... )
+char* _bprint( char* p, char* end, const char* format, ... ) __DEBUG__;
+char* _bprint( char* p, char* end, const char* format, ... )
{
int avail, n;
va_list args;
@@ -278,7 +290,7 @@ _bprint( char* p, char* end, const char* format, ... )
}
/* add a hex value to a bounded buffer, up to 8 digits */
-static char*
+char*
_bprint_hex( char* p, char* end, unsigned value, int numDigits )
{
char text[sizeof(unsigned)*2];
@@ -291,7 +303,7 @@ _bprint_hex( char* p, char* end, unsigned value, int numDigits )
}
/* add the hexadecimal dump of some memory area to a bounded buffer */
-static char*
+char*
_bprint_hexdump( char* p, char* end, const uint8_t* data, int datalen )
{
int lineSize = 16;
@@ -330,20 +342,17 @@ _bprint_hexdump( char* p, char* end, const uint8_t* data, int datalen )
}
/* dump the content of a query of packet to the log */
-static void
-XLOG_BYTES( const void* base, int len )
+void XLOG_BYTES( const void* base, int len ) __DEBUG__;
+void XLOG_BYTES( const void* base, int len )
{
- char buff[1024];
- char* p = buff, *end = p + sizeof(buff);
-
- p = _bprint_hexdump(p, end, base, len);
- XLOG("%s",buff);
-}
+ if (DEBUG_DATA) {
+ char buff[1024];
+ char* p = buff, *end = p + sizeof(buff);
-#else /* !DEBUG */
-# define XLOG(...) ((void)0)
-# define XLOG_BYTES(a,b) ((void)0)
-#endif
+ p = _bprint_hexdump(p, end, base, len);
+ XLOG("%s",buff);
+ }
+} __DEBUG__
static time_t
_time_now( void )