diff options
Diffstat (limited to 'common/debug.c')
| -rw-r--r-- | common/debug.c | 51 | 
1 files changed, 29 insertions, 22 deletions
diff --git a/common/debug.c b/common/debug.c index a1c336b..7a593fc 100644 --- a/common/debug.c +++ b/common/debug.c @@ -30,10 +30,13 @@  #include <stdint.h>  #include <stdlib.h>  #include <time.h> +#ifndef _WIN32 +#include <sys/time.h> +#endif +#include "src/idevice.h"  #include "debug.h"  #include "libimobiledevice/libimobiledevice.h" -#include "src/idevice.h"  #ifndef STRIP_DEBUG_CODE  #include "asprintf.h" @@ -46,32 +49,36 @@ void internal_set_debug_level(int level)  	debug_level = level;  } -#define MAX_PRINT_LEN 16*1024 +#define MAX_PRINT_LEN (16*1024)  #ifndef STRIP_DEBUG_CODE  static void debug_print_line(const char *func, const char *file, int line, const char *buffer)  { -	char *str_time = NULL; -	char *header = NULL; +	char str_time[24]; +#ifdef _WIN32 +	SYSTEMTIME lt; +	GetLocalTime(<); +	snprintf(str_time, 24, "%02d:%02d:%02d.%03d", lt.wHour, lt.wMinute, lt.wSecond, lt.wMilliseconds); +#else +#ifdef HAVE_GETTIMEOFDAY +	struct timeval tv; +	struct tm *tp; +	gettimeofday(&tv, NULL); +#ifdef HAVE_LOCALTIME_R +	struct tm tp_; +	tp = localtime_r(&tv.tv_sec, &tp_); +#else +	tp = localtime(&tv.tv_sec); +#endif +	strftime(str_time, 9, "%H:%M:%S", tp); +	snprintf(str_time+8, 10, ".%03d", (int)tv.tv_usec/1000); +#else  	time_t the_time; -  	time(&the_time); -	str_time = (char*)malloc(255); -	strftime(str_time, 254, "%H:%M:%S", localtime (&the_time)); - -	/* generate header text */ -	(void)asprintf(&header, "%s %s:%d %s()", str_time, file, line, func); -	free (str_time); - -	/* trim ending newlines */ - -	/* print header */ -	fprintf(stderr, "%s: ", header); - -	/* print actual debug content */ -	fprintf(stderr, "%s\n", buffer); - -	free (header); +	strftime(str_time, 15, "%H:%M:%S", localtime (&the_time)); +#endif +#endif +	fprintf(stderr, "%s %s:%d %s(): %s\n", str_time, file, line, func, buffer);  }  #endif @@ -86,7 +93,7 @@ void debug_info_real(const char *func, const char *file, int line, const char *f  	/* run the real fprintf */  	va_start(args, format); -	(void)vasprintf(&buffer, format, args); +	if(vasprintf(&buffer, format, args)<0){}  	va_end(args);  	debug_print_line(func, file, line, buffer);  | 
