]>
Commit | Line | Data |
---|---|---|
9915e08f JH |
1 | #include "test-tool.h" |
2 | #include "git-compat-util.h" | |
3 | ||
4 | /* | |
5 | * Read stdin and print a hexdump to stdout. | |
6 | */ | |
126e3b3d | 7 | int cmd__hexdump(int argc UNUSED, const char **argv UNUSED) |
9915e08f JH |
8 | { |
9 | char buf[1024]; | |
10 | ssize_t i, len; | |
11 | int have_data = 0; | |
12 | ||
13 | for (;;) { | |
14 | len = xread(0, buf, sizeof(buf)); | |
15 | if (len < 0) | |
16 | die_errno("failure reading stdin"); | |
17 | if (!len) | |
18 | break; | |
19 | ||
20 | have_data = 1; | |
21 | ||
22 | for (i = 0; i < len; i++) | |
23 | printf("%02x ", (unsigned char)buf[i]); | |
24 | } | |
25 | ||
26 | if (have_data) | |
27 | putchar('\n'); | |
28 | ||
29 | return 0; | |
30 | } |