hexdump - display buffer content in hexadecimal and ascii
#include "hexdump.h"
static void hexdump(unsigned int address, const unsigned char *buf, unsigned int bufsize);
static void fhexdump(FILE *f, unsigned int address , const unsigned char *buf, unsigned int bufsize);
static int DUMPHEADER = 1;
static int DUMPFOOTER = 1;
static int DUMPADDR = 1;
static unsigned int ROWSIZE = 0x10;
static char EMPTYBYTE = ' ';
hexdump imitates what hexdump(1) does when it is invoked along with -C argument. The function hexdump(3) writes output to stdout, the standard output stream; fhexdump(3) writes output to the given output stream.
The hexdump function dumps the bufsize bytes of input buf by rows, first in hexadecimal and then in ASCII. Non-printable characters are replaced by a dot `.'.
The size of dumped rows is set using ROWSIZE global. This variable is set by default to 0x10 to display 16 bytes per row.
When buf does not fill the row, hexdump prints an empty space `` ' to feed the row. This character is set using the global EMPTYBYTE.
if DUMPADDR is non-null, each lines is prefixed by the address + current row.
if DUMPFOOTER is non-null, hexdump displays the address beyong the data of as footer (i.e. address + bufsize).
if DUMPHEADER is non-null, hexdump displays the following header at first line
@address: 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f
Note that @address: and the number of bytes depends on both DUMPADDR and ROWSIZE values.
hexdump.c is a good example of how to use the hexdump function.
Written by Gaël PORTAY gael.portay@gmail.com
Copyright (c) 2015-2017 Gaël PORTAY
This program is free software: you can redistribute it and/or modify it under the terms of the MIT License.