dd: truncate file when using seek= - ubase - suckless linux base utils | |
git clone git://git.suckless.org/ubase | |
Log | |
Files | |
Refs | |
README | |
LICENSE | |
--- | |
commit 596663c1b1f140c10ba1facede783201d6a876a7 | |
parent e358d74a805829dddf987ff62f42c7631df48e88 | |
Author: Eivind Uggedal <[email protected]> | |
Date: Tue, 15 Mar 2016 21:06:28 +0000 | |
dd: truncate file when using seek= | |
Diffstat: | |
M dd.c | 9 +++++++++ | |
1 file changed, 9 insertions(+), 0 deletions(-) | |
--- | |
diff --git a/dd.c b/dd.c | |
@@ -108,6 +108,15 @@ prepare_copy(struct dd_config *ddc, int *ifd, int *ofd) | |
return -1; | |
} | |
+ if (ddc->seek) { | |
+ if (fstat(*ofd, &st) < 0) | |
+ return -1; | |
+ if (!S_ISREG(st.st_mode)) | |
+ ; | |
+ else if (ftruncate(*ofd, ddc->seek) < 0) | |
+ return -1; | |
+ } | |
+ | |
if (lseek(*ifd, ddc->skip, SEEK_CUR) < 0) { | |
char buffer[ddc->bs]; | |
for (uint64_t i = 0; i < ddc->skip; i += ddc->bs) { |