+
+void do_byte_hexdump(FILE *fp, unsigned char *buf, size_t bufsize)
+{
+ size_t i, j, max;
+ int suppress = -1;
+
+ for (i = 0; i < bufsize; i += 16) {
+ max = (bufsize - i > 16) ? 16 : bufsize - i;
+ if (suppress < 0) {
+ if (i && memcmp(buf + i, buf + i - max, max) == 0) {
+ suppress = i;
+ fprintf(fp, "*\n");
+ continue;
+ }
+ } else {
+ if (memcmp(buf + i, buf + suppress, max) == 0)
+ continue;
+ suppress = -1;
+ }
+ fprintf(fp, "%04o ", (unsigned int)i);
+ for (j = 0; j < 16; j++) {
+ if (j < max)
+ fprintf(fp, "%02x", buf[i+j]);
+ else
+ fprintf(fp, " ");
+ if ((j % 2) == 1)
+ fprintf(fp, " ");
+ }
+ fprintf(fp, " ");
+ for (j = 0; j < max; j++)
+ fprintf(fp, "%c", isprint(buf[i+j]) ? buf[i+j] : '.');
+ fprintf(fp, "\n");
+ }
+ fprintf(fp, "\n");
+}