qemu-patch-raspberry4/util/hexdump.c
Philippe Mathieu-Daudé b42581f5bb util/hexdump: Reorder qemu_hexdump() arguments
qemu_hexdump()'s pointer to the buffer and length of the
buffer are closely related arguments but are widely separated
in the argument list order (also, the format of <stdio.h>
function prototypes is usually to have the FILE* argument
coming first).

Reorder the arguments as "fp, prefix, buf, size" which is
more logical.

Suggested-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Reviewed-by: Edgar E. Iglesias <edgar.iglesias@xilinx.com>
Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>
Message-Id: <20200822180950.1343963-3-f4bug@amsat.org>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
2020-09-11 21:25:59 +02:00

52 lines
1.4 KiB
C

/*
* Helper to hexdump a buffer
*
* Copyright (c) 2013 Red Hat, Inc.
* Copyright (c) 2013 Gerd Hoffmann <kraxel@redhat.com>
* Copyright (c) 2013 Peter Crosthwaite <peter.crosthwaite@xilinx.com>
* Copyright (c) 2013 Xilinx, Inc
*
* This work is licensed under the terms of the GNU GPL, version 2. See
* the COPYING file in the top-level directory.
*
* Contributions after 2012-01-13 are licensed under the terms of the
* GNU GPL, version 2 or (at your option) any later version.
*/
#include "qemu/osdep.h"
#include "qemu-common.h"
void qemu_hexdump(FILE *fp, const char *prefix,
const void *bufptr, size_t size)
{
const char *buf = bufptr;
unsigned int b, len, i, c;
for (b = 0; b < size; b += 16) {
len = size - b;
if (len > 16) {
len = 16;
}
fprintf(fp, "%s: %04x:", prefix, b);
for (i = 0; i < 16; i++) {
if ((i % 4) == 0) {
fprintf(fp, " ");
}
if (i < len) {
fprintf(fp, " %02x", (unsigned char)buf[b + i]);
} else {
fprintf(fp, " ");
}
}
fprintf(fp, " ");
for (i = 0; i < len; i++) {
c = buf[b + i];
if (c < ' ' || c > '~') {
c = '.';
}
fprintf(fp, "%c", c);
}
fprintf(fp, "\n");
}
}