summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
Diffstat (limited to 'src/common')
-rw-r--r--src/common/utils.c39
-rw-r--r--src/common/utils.h8
2 files changed, 22 insertions, 25 deletions
diff --git a/src/common/utils.c b/src/common/utils.c
index 00b6dc290..15d1d2e68 100644
--- a/src/common/utils.c
+++ b/src/common/utils.c
@@ -20,41 +20,40 @@
#include <sys/stat.h>
#endif
-#ifdef UTIL_DUMP
-void dump(const unsigned char* buffer, int num)
+// generate a hex dump of the first 'length' bytes of 'buffer'
+void dump(FILE* fp, const unsigned char* buffer, int length)
{
- int icnt, jcnt;
+ int i, j;
- printf(" Hex ASCII\n");
- printf(" ----------------------------------------------- ----------------");
+ fprintf(fp, " Hex ASCII\n");
+ fprintf(fp, " ----------------------------------------------- ----------------");
- for (icnt = 0; icnt < num; icnt += 16)
+ for (i = 0; i < length; i += 16)
{
- printf("\n%p ", &buffer[icnt]);
- for (jcnt = icnt; jcnt < icnt + 16; ++jcnt)
+ fprintf(fp, "\n%p ", &buffer[i]);
+ for (j = i; j < i + 16; ++j)
{
- if (jcnt < num)
- printf("%02hX ", buffer[jcnt]);
+ if (j < length)
+ fprintf(fp, "%02hX ", buffer[j]);
else
- printf(" ");
+ fprintf(fp, " ");
}
- printf(" | ");
+ fprintf(fp, " | ");
- for (jcnt = icnt; jcnt < icnt + 16; ++jcnt)
+ for (j = i; j < i + 16; ++j)
{
- if (jcnt < num) {
- if (buffer[jcnt] > 31 && buffer[jcnt] < 127)
- printf("%c", buffer[jcnt]);
+ if (j < length) {
+ if (buffer[j] > 31 && buffer[j] < 127)
+ fprintf(fp, "%c", buffer[j]);
else
- printf(".");
+ fprintf(fp, ".");
} else
- printf(" ");
+ fprintf(fp, " ");
}
}
- printf("\n");
+ fprintf(fp, "\n");
}
-#endif
// Allocate a StringBuf [MouseJstr]
struct StringBuf * StringBuf_Malloc()
diff --git a/src/common/utils.h b/src/common/utils.h
index 66ce04c99..898a63ab4 100644
--- a/src/common/utils.h
+++ b/src/common/utils.h
@@ -4,13 +4,11 @@
#ifndef _UTILS_H_
#define _UTILS_H_
+#include <stdio.h>
#include <stdarg.h>
-// Function that dumps the hex of the first num bytes of the buffer to the screen
-//#define UTIL_DUMP
-#ifdef UTIL_DUMP
-void dump(const unsigned char* buffer, int num);
-#endif
+// generate a hex dump of the first 'length' bytes of 'buffer'
+void dump(FILE* fp, const unsigned char* buffer, int length);
struct StringBuf {
char *buf_;