git
[Ported from github.com/git/git] Sync with Git 2.56.1
Brought by drakestapleton
git / t / helper / test-base85.c
| 1 | #include "test-tool.h" |
| 2 | #include "base85.h" |
| 3 | |
| 4 | #define MAX_INPUT_BUF BASE85_CHUNK_SIZE * 1024 |
| 5 | |
| 6 | static const char *base85_usage = "test-tool base85 chunk-encode"; |
| 7 | |
| 8 | static void print_binary_diff_line(char line[71], int len, void *output_data UNUSED) |
| 9 | { |
| 10 | fwrite(line, 1, len, stdout); |
| 11 | } |
| 12 | |
| 13 | static void base85_chunk(void) |
| 14 | { |
| 15 | unsigned char *input = xmalloc(MAX_INPUT_BUF); |
| 16 | |
| 17 | for (;;) { |
| 18 | ssize_t len = read_in_full(0, input, MAX_INPUT_BUF); |
| 19 | if (len < 0) |
| 20 | die_errno("read error"); |
| 21 | |
| 22 | chunk_and_encode85(input, len, print_binary_diff_line, NULL); |
| 23 | if (len < MAX_INPUT_BUF) |
| 24 | break; |
| 25 | } |
| 26 | |
| 27 | putc('\n', stdout); |
| 28 | free(input); |
| 29 | } |
| 30 | |
| 31 | int cmd__base85(int argc, const char **argv) |
| 32 | { |
| 33 | if (argc != 2) |
| 34 | usage(base85_usage); |
| 35 | |
| 36 | if (!strcmp(argv[1], "chunk-encode")) { |
| 37 | base85_chunk(); |
| 38 | } else { |
| 39 | error("unknown subcommand: %s", argv[1]); |
| 40 | usage(base85_usage); |
| 41 | } |
| 42 | |
| 43 | return 0; |
| 44 | } |