diff options
| author | Ron Yorston <rmy@pobox.com> | 2025-06-16 09:16:49 +0100 |
|---|---|---|
| committer | Ron Yorston <rmy@pobox.com> | 2025-06-16 09:16:49 +0100 |
| commit | b9fa01c547dc09ff26cb45d8c54cd2c5c5701142 (patch) | |
| tree | 2ea1cf0f32b12c42534eec5552677ab396a6dc7e /coreutils | |
| parent | 143f43d75e5f210c5876c2f73bb842e4f08110a6 (diff) | |
| download | busybox-w32-b9fa01c547dc09ff26cb45d8c54cd2c5c5701142.tar.gz busybox-w32-b9fa01c547dc09ff26cb45d8c54cd2c5c5701142.tar.bz2 busybox-w32-b9fa01c547dc09ff26cb45d8c54cd2c5c5701142.zip | |
truncate: make new region of file sparse
On Linux when 'truncate' is used to create or extend a file the
new region is sparse. Do the same on Windows.
If the file is really being truncated, do not change its sparseness.
Adds 144 bytes.
(GitHub issue #501)
Diffstat (limited to 'coreutils')
| -rw-r--r-- | coreutils/truncate.c | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/coreutils/truncate.c b/coreutils/truncate.c index 8826e6b4c..87a47bb09 100644 --- a/coreutils/truncate.c +++ b/coreutils/truncate.c | |||
| @@ -73,6 +73,12 @@ int truncate_main(int argc UNUSED_PARAM, char **argv) | |||
| 73 | * do not report error, exitcode is also 0. | 73 | * do not report error, exitcode is also 0. |
| 74 | */ | 74 | */ |
| 75 | } else { | 75 | } else { |
| 76 | #if ENABLE_PLATFORM_MINGW32 | ||
| 77 | struct stat st; | ||
| 78 | |||
| 79 | if (fstat(fd, &st) == 0 && size > st.st_size) | ||
| 80 | make_sparse(fd, st.st_size, size); | ||
| 81 | #endif | ||
| 76 | if (ftruncate(fd, size) == -1) { | 82 | if (ftruncate(fd, size) == -1) { |
| 77 | bb_perror_msg("%s: truncate", *argv); | 83 | bb_perror_msg("%s: truncate", *argv); |
| 78 | ret = EXIT_FAILURE; | 84 | ret = EXIT_FAILURE; |
