Overview

A set of C functions to create data dumps similar to "hexdump -C".

It's also massively faster than hexhump: on my system for dumping into
/dev/null a 10MB file filled with /dev/urandom "hexdump -C" takes 4.8
seconds versus only 0.12 seconds with these functions.

This code consists of 3 functions:

  void hexdump_init(struct hexdump *, FILE *);
  void hexdump(struct hexdump *, void *, size_t);
  void hexdump_finish(struct hexdump *);

This sample program should tell you all you need to know:

$ cat simple.c
#include <stdlib.h>
#include <string.h>
#include "hexdump.h"

int main()
{
  struct hexdump hd;
  char           c;

  hexdump_init(&hd, stdout);

  hexdump(&hd, "Hello, world!", strlen("Hello, world!"));

  for (c = 0; c < 100; c++)
    hexdump(&hd, &c, 1);

  hexdump_finish(&hd);

  return EXIT_SUCCESS;
}

$ cc -o simple -O2 -Wall hexdump.c simple.c

$ ./simple
00000000  48 65 6c 6c 6f 2c 20 77  6f 72 6c 64 21 00 01 02  |Hello, world!...|
00000010  03 04 05 06 07 08 09 0a  0b 0c 0d 0e 0f 10 11 12  |................|
00000020  13 14 15 16 17 18 19 1a  1b 1c 1d 1e 1f 20 21 22  |............. !"|
00000030  23 24 25 26 27 28 29 2a  2b 2c 2d 2e 2f 30 31 32  |#$%&'()*+,-./012|
00000040  33 34 35 36 37 38 39 3a  3b 3c 3d 3e 3f 40 41 42  |3456789:;<=>?@AB|
00000050  43 44 45 46 47 48 49 4a  4b 4c 4d 4e 4f 50 51 52  |CDEFGHIJKLMNOPQR|
00000060  53 54 55 56 57 58 59 5a  5b 5c 5d 5e 5f 60 61 62  |STUVWXYZ[\]^_`ab|
00000070  63                                                |c|
00000071