]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
tests: dd: check that files are opened with O_TRUNC
authorCollin Funk <collin.funk1@gmail.com>
Mon, 22 Jun 2026 03:45:09 +0000 (20:45 -0700)
committerCollin Funk <collin.funk1@gmail.com>
Thu, 25 Jun 2026 04:08:33 +0000 (21:08 -0700)
* tests/dd/misc.sh: Add the test case.

tests/dd/misc.sh

index aa776b13794abf8cc772022a3f9a40570f1c7032..5e2eb8ed5055e3fd2485e8072c0176c507db3d21 100755 (executable)
@@ -19,6 +19,7 @@
 
 . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
 print_ver_ dd
+uses_strace_
 export LC_ALL=C
 
 tmp_in=dd-in
@@ -129,5 +130,16 @@ if test -c /dev/tty && >/dev/tty; then
   dd if=/dev/null of=/dev/tty || fail=1
 fi
 
+# Ensure that the output file is opened with O_TRUNC.
+if strace -o /dev/null -e inject=truncate,ftruncate:error=EIO true; then
+  echo a > $tmp_out || framework_failure_
+  strace --quiet=all -o /dev/null \
+    -e inject=truncate,ftruncate:error=EIO -P $tmp_out \
+    dd if=/dev/null of=$tmp_out status=none skip=1B >out 2>err || fail=1
+  compare /dev/null out || fail=1
+  compare /dev/null err || fail=1
+  compare /dev/null $tmp_out || fail=1
+fi
+
 
 Exit $fail