util/hexdump: Use a GString for qemu_hexdump_line
Allocate a new, or append to an existing GString instead of using a fixed sized buffer. Require the caller to determine the length of the line -- do not bound len here. Signed-off-by: Richard Henderson <richard.henderson@linaro.org> Message-Id: <20240412073346.458116-4-richard.henderson@linaro.org>
This commit is contained in:
parent
f1572ab947
commit
53ee5f551e
3 changed files with 34 additions and 22 deletions
|
|
@ -282,12 +282,17 @@ static inline const char *yes_no(bool b)
|
|||
*/
|
||||
int parse_debug_env(const char *name, int max, int initial);
|
||||
|
||||
/*
|
||||
* Hexdump a line of a byte buffer into a hexadecimal/ASCII buffer
|
||||
/**
|
||||
* qemu_hexdump_line:
|
||||
* @str: GString into which to append
|
||||
* @buf: buffer to dump
|
||||
* @len: number of bytes to dump
|
||||
*
|
||||
* Append @len bytes of @buf as hexadecimal into @str.
|
||||
* If @str is NULL, allocate a new string and return it;
|
||||
* otherwise return @str.
|
||||
*/
|
||||
#define QEMU_HEXDUMP_LINE_BYTES 16 /* Number of bytes to dump */
|
||||
#define QEMU_HEXDUMP_LINE_LEN 75 /* Number of characters in line */
|
||||
void qemu_hexdump_line(char *line, const void *bufptr, size_t len);
|
||||
GString *qemu_hexdump_line(GString *str, const void *buf, size_t len);
|
||||
|
||||
/*
|
||||
* Hexdump a buffer to a file. An optional string prefix is added to every line
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue