Skip to content

Commit 580f9fd

Browse files
committed
Add hexdump for debugging
Signed-off-by: Klaus Kämpf <kkaempf@gmail.com>
1 parent f68cb9a commit 580f9fd

File tree

3 files changed

+53
-1
lines changed

3 files changed

+53
-1
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ MANSEC=1
3636
MANDIR=/usr/share/man/man$(MANSEC)
3737
DISTFILES=README vmsbackup.1 Makefile vmsbackup.c match.c NEWS build.com dclmain.c getoptmain.c vmsbackup.cld vmsbackup.h sysdep.h
3838

39-
vmsbackup: vmsbackup.o match.o getoptmain.o
39+
vmsbackup: vmsbackup.o match.o getoptmain.o hexdump.o
4040

4141
vmsbackup.o : vmsbackup.c
4242
match.o : match.c

hexdump.c

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
#include <stdarg.h>
4+
#include <unistd.h>
5+
#include <ctype.h>
6+
7+
void
8+
hexdump (const unsigned char *ptr, int size, FILE *out)
9+
/*
10+
* hex dump 'size' bytes starting at 'ptr'
11+
*/
12+
{
13+
const unsigned char *lptr = ptr;
14+
int count = 0;
15+
long start = 0;
16+
17+
while (size-- > 0)
18+
{
19+
if ((count % 16) == 0)
20+
fprintf (out, "\t%08lx:", start);
21+
fprintf (out, " %02x", *ptr++);
22+
count++;
23+
start++;
24+
if (size == 0)
25+
{
26+
while ((count % 16) != 0)
27+
{
28+
fprintf(out, " ");
29+
count++;
30+
}
31+
}
32+
if ((count % 16) == 0)
33+
{
34+
fprintf (out, " ");
35+
while (lptr < ptr)
36+
{
37+
unsigned char c = *lptr&0x7f;
38+
c = ((c < 32)||(c == 0x7f))?'.':c;
39+
fprintf (out, "%c", c);
40+
lptr++;
41+
}
42+
fprintf(out,"\n");
43+
}
44+
}
45+
if ((count % 16) != 0)
46+
fprintf(out, "\n");
47+
48+
fflush (out);
49+
return;
50+
}
51+

hexdump.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
void hexdump (const unsigned char *ptr, int size, FILE *out);

0 commit comments

Comments
 (0)