[hackers] [ubase] dd: implement conv=notrunc support || Eivind Uggedal

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

commit e0dc3f9546b3cd839aef8e58376c6295679a5ed5
Author: Eivind Uggedal <eivind_AT_uggedal.com>
AuthorDate: Wed Mar 16 09:23:50 2016 +0000
Commit: sin <sin_AT_2f30.org>
CommitDate: Wed Mar 16 10:17:51 2016 +0000

    dd: implement conv=notrunc support

diff --git a/dd.1 b/dd.1
index 31fe00e..477e99f 100644
--- a/dd.1
+++ b/dd.1
_AT_@ -61,4 +61,6 @@ blocks from the beginning of the output before copying.
 Skip
 .Ar N
 blocks from the beginning of the input before copying.
+.It Ar conv=notrunc
+Do not truncate the output file.
 .El
diff --git a/dd.c b/dd.c
index 912ca83..cc05d40 100644
--- a/dd.c
+++ b/dd.c
_AT_@ -32,7 +32,7 @@ struct dd_config {
         uint64_t skip, seek, count, b_in, b_out, rec_in, rec_out;
         off_t fsize;
         blksize_t bs;
- char quiet, nosync, direct;
+ char quiet, nosync, notrunc, direct;
         time_t t_start, t_end;
 };
 
_AT_@ -99,7 +99,7 @@ prepare_copy(struct dd_config *ddc, int *ifd, int *ofd)
                 return -1;
         }
 
- if (!ddc->seek)
+ if (!ddc->seek && !ddc->notrunc)
                 flo |= O_TRUNC;
 
         if (!ddc->out) *ofd = 1;
_AT_@ -108,7 +108,7 @@ prepare_copy(struct dd_config *ddc, int *ifd, int *ofd)
                 return -1;
         }
 
- if (ddc->seek) {
+ if (ddc->seek && !ddc->notrunc) {
                 if (fstat(*ofd, &st) < 0)
                         return -1;
                 if (!S_ISREG(st.st_mode))
_AT_@ -238,7 +238,8 @@ static void
 usage(void)
 {
         eprintf("usage: %s [-h] [if=infile] [of=outfile] [bs[=N]] [seek=N] "
- "[skip=N] [count=N] [direct] [quiet] [nosync]\n", argv0);
+ "[skip=N] [count=N] [direct] [quiet] [nosync]"
+ "[conv=notrunc]\n", argv0);
 }
 
 int
_AT_@ -278,6 +279,8 @@ main(int argc, char *argv[])
                         config.quiet = 1;
                 else if (strcmp(argv[i], "nosync") == 0)
                         config.nosync = 1;
+ else if (strcmp(argv[i], "conv=notrunc") == 0)
+ config.notrunc = 1;
                 else if (strcmp(argv[i], "-h") == 0)
                         usage();
         }
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:29 CET