test-genzeros: avoid raw write(2)

This test helper feeds 256kB of data at once to a single invocation of the write(2) system call, which may be too much for some platforms. Call our xwrite() wrapper that knows to honor MAX_IO_SIZE limit and cope with short writes due to EINTR instead, and die a bit more loudly by calling die_errno() when xwrite() indicates an error. Reported-by: Randall S. Becker <rsbecker@nexbridge.com> Helped-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Feb 15, 2023 at 18:56 UTC 58eab6ff13924edd156d45bd8e0a947b8f8e07e9
1 file changed +6 -5
t/helper/test-genzeros.c
+6 -5
@@ -17,15 +17,16 @@ int cmd__genzeros(int argc, const char **argv)
17
18 /* Writing out individual NUL bytes is slow... */
19 while (count < 0)
20 - if (write(1, zeros, ARRAY_SIZE(zeros)) < 0)
21 - return -1;
20 + if (xwrite(1, zeros, ARRAY_SIZE(zeros)) < 0)
21 + die_errno("write error");
22
23 while (count > 0) {
24 - n = write(1, zeros, count < ARRAY_SIZE(zeros) ?
25 - count : ARRAY_SIZE(zeros));
24 + n = xwrite(1, zeros,
25 + count < ARRAY_SIZE(zeros)
26 + ? count : ARRAY_SIZE(zeros));
27
28 if (n < 0)
28 - return -1;
29 + die_errno("write error");
30
31 count -= n;
32 }