From 3cdebafe3f05fe6852f9ba97a9243b5d571a6b51 Mon Sep 17 00:00:00 2001 From: Jeffery Miller Date: Wed, 16 Apr 2025 18:54:01 -0500 Subject: [PATCH] dd: Add support for conv=nocreat With `conv=nocreat` set O_CREAT will not be set when creating the output file, causing an error if of does not exist. Test: dd if=/dev/zero of=/tmp/doesnotexist conv=nocreat count=1 --- toys/posix/dd.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/toys/posix/dd.c b/toys/posix/dd.c index 7fc721fc..ebd55f10 100644 --- a/toys/posix/dd.c +++ b/toys/posix/dd.c @@ -52,7 +52,7 @@ struct dd_flag { }; static const struct dd_flag dd_conv[] = TAGGED_ARRAY(DD_conv, - {"fsync"}, {"noerror"}, {"notrunc"}, {"sync"}, // TODO sparse excl nocreat + {"fsync"}, {"noerror"}, {"notrunc"}, {"sync"}, {"nocreat"}, // TODO sparse excl ); static const struct dd_flag dd_iflag[] = TAGGED_ARRAY(DD_iflag, @@ -149,7 +149,7 @@ void dd_main() count = ULLONG_MAX, buflen; long long len; struct iovec iov[2]; - int opos, olen, ifd = 0, ofd = 1, trunc = O_TRUNC, ii; + int opos, olen, ifd = 0, ofd = 1, trunc = O_TRUNC, creat = O_CREAT, ii; unsigned conv = 0, iflag = 0, oflag = 0; TT.show_xfer = TT.show_records = 1; @@ -186,10 +186,11 @@ void dd_main() buf = xmalloc(buflen = ibs+obs*!bs); if (buflen