Skip to content

Commit 58eab6f

Browse files
committed
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 <[email protected]> Helped-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c48035d commit 58eab6f

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

t/helper/test-genzeros.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,16 @@ int cmd__genzeros(int argc, const char **argv)
1717

1818
/* Writing out individual NUL bytes is slow... */
1919
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");
2222

2323
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));
2627

2728
if (n < 0)
28-
return -1;
29+
die_errno("write error");
2930

3031
count -= n;
3132
}

0 commit comments

Comments
 (0)