]>
Commit | Line | Data |
---|---|---|
d5cfd142 JS |
1 | #include "test-tool.h" |
2 | #include "git-compat-util.h" | |
3 | ||
4 | int cmd__genzeros(int argc, const char **argv) | |
5 | { | |
df7000cd JS |
6 | /* static, so that it is NUL-initialized */ |
7 | static const char zeros[256 * 1024]; | |
cbc985a1 | 8 | intmax_t count; |
df7000cd | 9 | ssize_t n; |
d5cfd142 JS |
10 | |
11 | if (argc > 2) { | |
12 | fprintf(stderr, "usage: %s [<count>]\n", argv[0]); | |
13 | return 1; | |
14 | } | |
15 | ||
cbc985a1 | 16 | count = argc > 1 ? strtoimax(argv[1], NULL, 0) : -1; |
d5cfd142 | 17 | |
df7000cd JS |
18 | /* Writing out individual NUL bytes is slow... */ |
19 | while (count < 0) | |
58eab6ff JH |
20 | if (xwrite(1, zeros, ARRAY_SIZE(zeros)) < 0) |
21 | die_errno("write error"); | |
df7000cd JS |
22 | |
23 | while (count > 0) { | |
58eab6ff JH |
24 | n = xwrite(1, zeros, |
25 | count < ARRAY_SIZE(zeros) | |
26 | ? count : ARRAY_SIZE(zeros)); | |
df7000cd JS |
27 | |
28 | if (n < 0) | |
58eab6ff | 29 | die_errno("write error"); |
df7000cd JS |
30 | |
31 | count -= n; | |
d5cfd142 JS |
32 | } |
33 | ||
34 | return 0; | |
35 | } |