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