Make bionic compile even if resolver debugging is enabled.

The code now compiles with all combinations of DEBUG and
DEBUG_DATA except DEBUG_DATA=1, DEBUG=0, which is unsupported.

Change-Id: I9035a65c649df73092f1fc0864ae1cdd9a14aa3b
This commit is contained in:
Lorenzo Colitti 2014-11-28 11:47:13 +09:00
parent d1668a71df
commit 616344d169
1 changed files with 33 additions and 24 deletions

View File

@ -28,6 +28,8 @@
#include "resolv_cache.h" #include "resolv_cache.h"
#include <resolv.h> #include <resolv.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <time.h> #include <time.h>
@ -45,6 +47,8 @@
#include "resolv_netid.h" #include "resolv_netid.h"
#include "res_private.h" #include "res_private.h"
#include "private/libc_logging.h"
/* This code implements a small and *simple* DNS resolver cache. /* 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 * 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 */ /* set to 1 to debug query data */
#define DEBUG_DATA 0 #define DEBUG_DATA 0
#undef XLOG
#if DEBUG #if DEBUG
# include "private/libc_logging.h" #define __DEBUG__
# define XLOG(...) __libc_format_log(ANDROID_LOG_DEBUG,"libc",__VA_ARGS__) #else
#define __DEBUG__ __attribute__((unused))
#endif
#include <stdio.h> #undef XLOG
#include <stdarg.h>
#define XLOG(...) ({ \
if (DEBUG) { \
__libc_format_log(ANDROID_LOG_DEBUG,"libc",__VA_ARGS__); \
} else { \
((void)0); \
} \
})
/** BOUNDED BUFFER FORMATTING /** BOUNDED BUFFER FORMATTING
**/ **/
@ -205,7 +217,7 @@
*/ */
/* add a char to a bounded buffer */ /* add a char to a bounded buffer */
static char* char*
_bprint_c( char* p, char* end, int c ) _bprint_c( char* p, char* end, int c )
{ {
if (p < end) { if (p < end) {
@ -220,7 +232,7 @@ _bprint_c( char* p, char* end, int c )
} }
/* add a sequence of bytes to a bounded buffer */ /* add a sequence of bytes to a bounded buffer */
static char* char*
_bprint_b( char* p, char* end, const char* buf, int len ) _bprint_b( char* p, char* end, const char* buf, int len )
{ {
int avail = end - p; 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 */ /* add a string to a bounded buffer */
static char* char*
_bprint_s( char* p, char* end, const char* str ) _bprint_s( char* p, char* end, const char* str )
{ {
return _bprint_b(p, end, str, strlen(str)); return _bprint_b(p, end, str, strlen(str));
} }
/* add a formatted string to a bounded buffer */ /* add a formatted string to a bounded buffer */
static char* char* _bprint( char* p, char* end, const char* format, ... ) __DEBUG__;
_bprint( char* p, char* end, const char* format, ... ) char* _bprint( char* p, char* end, const char* format, ... )
{ {
int avail, n; int avail, n;
va_list args; 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 */ /* 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 ) _bprint_hex( char* p, char* end, unsigned value, int numDigits )
{ {
char text[sizeof(unsigned)*2]; 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 */ /* 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 ) _bprint_hexdump( char* p, char* end, const uint8_t* data, int datalen )
{ {
int lineSize = 16; 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 */ /* dump the content of a query of packet to the log */
static void void XLOG_BYTES( const void* base, int len ) __DEBUG__;
XLOG_BYTES( const void* base, int len ) void XLOG_BYTES( const void* base, int len )
{ {
char buff[1024]; if (DEBUG_DATA) {
char* p = buff, *end = p + sizeof(buff); char buff[1024];
char* p = buff, *end = p + sizeof(buff);
p = _bprint_hexdump(p, end, base, len); p = _bprint_hexdump(p, end, base, len);
XLOG("%s",buff); XLOG("%s",buff);
} }
} __DEBUG__
#else /* !DEBUG */
# define XLOG(...) ((void)0)
# define XLOG_BYTES(a,b) ((void)0)
#endif
static time_t static time_t
_time_now( void ) _time_now( void )