aboutsummaryrefslogtreecommitdiffstats
path: root/debug.c
diff options
context:
space:
mode:
Diffstat (limited to 'debug.c')
-rw-r--r--debug.c71
1 files changed, 71 insertions, 0 deletions
diff --git a/debug.c b/debug.c
new file mode 100644
index 0000000..b319b57
--- /dev/null
+++ b/debug.c
@@ -0,0 +1,71 @@
+#include "debug.h"
+
+#ifdef NEED_DEBUG_HELPER
+#include <stdio.h>
+#include <time.h>
+#include <sys/time.h>
+
+void debug_print_time()
+{
+ struct timeval debug_tv;
+ struct tm *debug_tm;
+ char debug_buffer[10];
+
+ gettimeofday(&debug_tv,NULL);
+ debug_tm=localtime(&debug_tv.tv_sec);
+ strftime(debug_buffer,10, "%T",debug_tm);
+ fprintf(stderr,"%s.%06d: ",debug_buffer,(int)debug_tv.tv_usec);
+}
+
+#endif
+
+#ifdef NEED_HEXDUMP_HELPER
+#include <stdio.h>
+
+void hexdump(unsigned char *data,int len)
+{
+ int count;
+ int count2;
+ int max;
+
+ for(count=0;count<len;count+=16)
+ {
+#ifdef SET_DEBUG_PRINT_PREFIX
+ fprintf(stderr,"%s",SET_DEBUG_PRINT_PREFIX);
+#endif
+ fprintf(stderr,"%04x ",count);
+
+ max=count+16;
+ if (max>len) max=len;
+
+ for(count2=count;count2<max;count2++)
+ {
+ if (count2%8==0) fprintf(stderr," ");
+ fprintf(stderr,"%02x ",data[count2]);
+ }
+
+ if (max<count+16)
+ {
+ for(count2=max;count2<count+16;count2++)
+ {
+ if (count2%8==0) fprintf(stderr," ");
+ fprintf(stderr," ");
+ }
+ }
+ fprintf(stderr," ");
+
+ for(count2=count;count2<max;count2++)
+ {
+ if (count2%8==0) fprintf(stderr," ");
+ if ((data[count2]>=32) && (data[count2]<127))
+ {
+ fprintf(stderr,"%c",data[count2]);
+ } else {
+ fprintf(stderr,".");
+ }
+ }
+
+ fprintf(stderr,"\n");
+ }
+}
+#endif