[hackers] [ubase] dd: truncate file when using seek= || Eivind Uggedal

From: <git_AT_suckless.org>
Date: Wed, 16 Mar 2016 11:18:16 +0100 (CET)

commit 596663c1b1f140c10ba1facede783201d6a876a7
Author: Eivind Uggedal <eivind_AT_uggedal.com>
AuthorDate: Tue Mar 15 21:06:28 2016 +0000
Commit: sin <sin_AT_2f30.org>
CommitDate: Wed Mar 16 10:17:51 2016 +0000

    dd: truncate file when using seek=

diff --git a/dd.c b/dd.c
index daa75fd..912ca83 100644
--- a/dd.c
+++ b/dd.c
_AT_@ -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) {
Received on Wed Mar 16 2016 - 11:18:16 CET

This archive was generated by hypermail 2.3.0 : Wed Mar 16 2016 - 11:24:27 CET