Statistics
| Branch: | Revision:

root / util / hexdump.c @ feature-archipelago

History | View | Annotate | Download (1002 Bytes)

1 6ff66f50 Peter Crosthwaite
/*
2 6ff66f50 Peter Crosthwaite
 * Helper to hexdump a buffer
3 6ff66f50 Peter Crosthwaite
 *
4 6ff66f50 Peter Crosthwaite
 * Copyright (c) 2013 Red Hat, Inc.
5 6ff66f50 Peter Crosthwaite
 * Copyright (c) 2013 Gerd Hoffmann <kraxel@redhat.com>
6 6ff66f50 Peter Crosthwaite
 * Copyright (c) 2013 Peter Crosthwaite <peter.crosthwaite@xilinx.com>
7 6ff66f50 Peter Crosthwaite
 * Copyright (c) 2013 Xilinx, Inc
8 6ff66f50 Peter Crosthwaite
 *
9 6ff66f50 Peter Crosthwaite
 * This work is licensed under the terms of the GNU GPL, version 2.  See
10 6ff66f50 Peter Crosthwaite
 * the COPYING file in the top-level directory.
11 6ff66f50 Peter Crosthwaite
 *
12 6ff66f50 Peter Crosthwaite
 * Contributions after 2012-01-13 are licensed under the terms of the
13 6ff66f50 Peter Crosthwaite
 * GNU GPL, version 2 or (at your option) any later version.
14 6ff66f50 Peter Crosthwaite
 */
15 6ff66f50 Peter Crosthwaite
16 6ff66f50 Peter Crosthwaite
#include "qemu-common.h"
17 6ff66f50 Peter Crosthwaite
18 3568ac2a Ed Maste
void qemu_hexdump(const char *buf, FILE *fp, const char *prefix, size_t size)
19 6ff66f50 Peter Crosthwaite
{
20 6ff66f50 Peter Crosthwaite
    unsigned int b;
21 6ff66f50 Peter Crosthwaite
22 6ff66f50 Peter Crosthwaite
    for (b = 0; b < size; b++) {
23 6ff66f50 Peter Crosthwaite
        if ((b % 16) == 0) {
24 6ff66f50 Peter Crosthwaite
            fprintf(fp, "%s: %04x:", prefix, b);
25 6ff66f50 Peter Crosthwaite
        }
26 6ff66f50 Peter Crosthwaite
        if ((b % 4) == 0) {
27 6ff66f50 Peter Crosthwaite
            fprintf(fp, " ");
28 6ff66f50 Peter Crosthwaite
        }
29 6ff66f50 Peter Crosthwaite
        fprintf(fp, " %02x", (unsigned char)buf[b]);
30 6ff66f50 Peter Crosthwaite
        if ((b % 16) == 15) {
31 6ff66f50 Peter Crosthwaite
            fprintf(fp, "\n");
32 6ff66f50 Peter Crosthwaite
        }
33 6ff66f50 Peter Crosthwaite
    }
34 6ff66f50 Peter Crosthwaite
    if ((b % 16) != 0) {
35 6ff66f50 Peter Crosthwaite
        fprintf(fp, "\n");
36 6ff66f50 Peter Crosthwaite
    }
37 6ff66f50 Peter Crosthwaite
}