diff options
author | Jeff Hostetler <jeffhost@microsoft.com> | 2022-05-27 00:47:20 +0300 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2022-05-27 01:59:27 +0300 |
commit | 9915e08f9bc4122a1d49101fff43be20a2ea6cb5 (patch) | |
tree | 8e823feff247e1ff0eb3f89bcd25a038b1c8e5d3 /t/helper/test-hexdump.c | |
parent | d6d58ff8abd382226980f00360e12e4bf91456e4 (diff) |
t/helper/hexdump: add helper to print hexdump of stdin
Co-authored-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Jeff Hostetler <jeffhost@microsoft.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 't/helper/test-hexdump.c')
-rw-r--r-- | t/helper/test-hexdump.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/t/helper/test-hexdump.c b/t/helper/test-hexdump.c new file mode 100644 index 0000000000..811e89c1bc --- /dev/null +++ b/t/helper/test-hexdump.c @@ -0,0 +1,30 @@ +#include "test-tool.h" +#include "git-compat-util.h" + +/* + * Read stdin and print a hexdump to stdout. + */ +int cmd__hexdump(int argc, const char **argv) +{ + char buf[1024]; + ssize_t i, len; + int have_data = 0; + + for (;;) { + len = xread(0, buf, sizeof(buf)); + if (len < 0) + die_errno("failure reading stdin"); + if (!len) + break; + + have_data = 1; + + for (i = 0; i < len; i++) + printf("%02x ", (unsigned char)buf[i]); + } + + if (have_data) + putchar('\n'); + + return 0; +} |