commit-reach(paint_down_to_common): plug two memory leaks
[git.git] / t / helper / test-hexdump.c
blob05f55eca21afb8792d60498fd9e1fc88d5499a72
1 #include "test-tool.h"
2 #include "git-compat-util.h"
4 /*
5 * Read stdin and print a hexdump to stdout.
6 */
7 int cmd__hexdump(int argc UNUSED, const char **argv UNUSED)
9 char buf[1024];
10 ssize_t i, len;
11 int have_data = 0;
13 for (;;) {
14 len = xread(0, buf, sizeof(buf));
15 if (len < 0)
16 die_errno("failure reading stdin");
17 if (!len)
18 break;
20 have_data = 1;
22 for (i = 0; i < len; i++)
23 printf("%02x ", (unsigned char)buf[i]);
26 if (have_data)
27 putchar('\n');
29 return 0;