]>
Commit | Line | Data |
---|---|---|
05cd988d | 1 | #include "test-tool.h" |
2 | #include "git-compat-util.h" | |
3 | ||
4 | ||
5 | int cmd__csprng(int argc, const char **argv) | |
6 | { | |
7 | unsigned long count; | |
8 | unsigned char buf[1024]; | |
9 | ||
10 | if (argc > 2) { | |
11 | fprintf(stderr, "usage: %s [<size>]\n", argv[0]); | |
12 | return 2; | |
13 | } | |
14 | ||
15 | count = (argc == 2) ? strtoul(argv[1], NULL, 0) : -1L; | |
16 | ||
17 | while (count) { | |
18 | unsigned long chunk = count < sizeof(buf) ? count : sizeof(buf); | |
19 | if (csprng_bytes(buf, chunk) < 0) { | |
20 | perror("failed to read"); | |
21 | return 5; | |
22 | } | |
23 | if (fwrite(buf, chunk, 1, stdout) != chunk) | |
24 | return 1; | |
25 | count -= chunk; | |
26 | } | |
27 | ||
28 | return 0; | |
29 | } |