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