scc

simple C compiler
git clone git://git.2f30.org/scc
Log | Files | Refs | README | LICENSE

commit e59a808bcb0b716a1dc48e81adadbf7633fa6c83
parent 0f3d2a9e70b4061b31bcf749c84fb8e6183e5020
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Mon, 27 Nov 2017 20:47:05 +0100

[objdump] Add printdata()

This function prints a binary dump of the data.

Diffstat:
objdump/main.c | 27+++++++++++++++++++++++++++
1 file changed, 27 insertions(+), 0 deletions(-)

diff --git a/objdump/main.c b/objdump/main.c @@ -149,6 +149,31 @@ printrelocs(struct myrohdr *hdr, FILE *fp) return 0; } +static int +printdata(struct myrohdr *hdr, FILE *fp) +{ + unsigned long off; + int c, i, j; + + puts("data:"); + for (off = 0; ; off += 32) { + printf("\t%08x:", off); + for (i = 0; i < 2; i++) { + for (j = 0; j < 16; j++) { + if ((c = getc(fp)) == EOF) + goto exit_loop; + printf(" %02X", c); + } + putchar('\t'); + } + putchar('\n'); + } + +exit_loop: + putchar('\n'); + return (ferror(fp)) ? -1 : 0; +} + int main(int argc, char *argv[]) { @@ -188,6 +213,8 @@ main(int argc, char *argv[]) goto wrong_file; if (printrelocs(&hdr, fp) < 0) goto wrong_file; + if (printdata(&hdr, fp) < 0) + goto wrong_file; goto close_file;