File: dump.c

package info (click to toggle)
hk-classes 0.8.2-2
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 10,872 kB
  • ctags: 16,819
  • sloc: cpp: 90,990; ansic: 78,016; sh: 8,385; python: 3,793; makefile: 292
file content (40 lines) | stat: -rw-r--r-- 706 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <ctype.h>
#include <string.h>
#include <stdio.h>

#ifdef DMALLOC
#include "dmalloc.h"
#endif

void buffer_dump(const void* buf, int start, size_t len)
{
	char asc[20];
	int j, k;

	memset(asc, 0, sizeof(asc));
	k = 0;
	for (j=start; j<start+len; j++) {
		int c = ((const unsigned char *)(buf))[j];
		if (k == 0) {
			fprintf(stdout, "%04x  ", j);
		}
		fprintf(stdout, "%02x ", c);
		asc[k] = isprint(c) ? c : '.';
		k++;
		if (k == 8) {
			fprintf(stdout, " ");
		}
		if (k == 16) {
			fprintf(stdout, "  %s\n", asc);
			memset(asc, 0, sizeof(asc));
			k = 0;
		}
	}
	for (j=k; j<16; j++) {
		fprintf(stdout, "   ");
	}
	if (k < 8) {
		fprintf(stdout, " ");
	}
	fprintf(stdout, "  %s\n", asc);
}