]> git.ipfire.org Git - thirdparty/coreutils.git/commit
cp: don’t allocate a separate zero buffer
authorPaul Eggert <eggert@cs.ucla.edu>
Wed, 6 Aug 2025 18:48:21 +0000 (11:48 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Tue, 16 Sep 2025 06:17:35 +0000 (23:17 -0700)
commit12d03a04446a8da4f5dc3cacd6888416687dd8a2
tree0de3012f937cb0b4fda1e25f4921e1fcbad89efb
parent3f9534a2abfd2f50fc9d4147c981ddabe64984d5
cp: don’t allocate a separate zero buffer

* src/copy-file-data.c (write_zeros): New args abuf, buf_size.
Use the lazily-allocated buffer, which most likely already exists,
rather than allocating a separate buffer just for zeros.
This makes the code more reentrant as there is no longer
a need for static storage here.  Although there is some CPU
overhead due to the need to zero out the buffer for each file,
the overhead is relatively small as the buffer is smallish
and should be cached.  All callers changed.
src/copy-file-data.c