tests: cache glibc version check
[git/gitster.git] / t / helper / test-genzeros.c
blob8ca988d6216e7895d8afea772e110b7eeaa875d1
1 #include "test-tool.h"
2 #include "git-compat-util.h"
4 int cmd__genzeros(int argc, const char **argv)
6 /* static, so that it is NUL-initialized */
7 static const char zeros[256 * 1024];
8 intmax_t count;
9 ssize_t n;
11 if (argc > 2) {
12 fprintf(stderr, "usage: %s [<count>]\n", argv[0]);
13 return 1;
16 count = argc > 1 ? strtoimax(argv[1], NULL, 0) : -1;
18 /* Writing out individual NUL bytes is slow... */
19 while (count < 0)
20 if (write(1, zeros, ARRAY_SIZE(zeros)) < 0)
21 return -1;
23 while (count > 0) {
24 n = write(1, zeros, count < ARRAY_SIZE(zeros) ?
25 count : ARRAY_SIZE(zeros));
27 if (n < 0)
28 return -1;
30 count -= n;
33 return 0;