1
0
mirror of git://git.suckless.org/ubase synced 2024-12-11 17:29:24 +00:00

dd: truncate file when using seek=

This commit is contained in:
Eivind Uggedal 2016-03-15 21:06:28 +00:00 committed by sin
parent e358d74a80
commit 596663c1b1

9
dd.c
View File

@ -108,6 +108,15 @@ prepare_copy(struct dd_config *ddc, int *ifd, int *ofd)
return -1; 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) { if (lseek(*ifd, ddc->skip, SEEK_CUR) < 0) {
char buffer[ddc->bs]; char buffer[ddc->bs];
for (uint64_t i = 0; i < ddc->skip; i += ddc->bs) { for (uint64_t i = 0; i < ddc->skip; i += ddc->bs) {