From 4c6f35ea529ebca9b2dfb6d7c79cade30118fd75 Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Tue, 9 Jul 2019 09:49:12 -0700 Subject: dd: fix seek= on stdout. --- tests/dd.test | 3 +++ toys/pending/dd.c | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/dd.test b/tests/dd.test index 3ad15f2e..d2d6033e 100644 --- a/tests/dd.test +++ b/tests/dd.test @@ -92,3 +92,6 @@ testing "conv=sync with IF" "dd conv=sync if=input $opt | head -n 1" "I WANT\n" # status=noxfer|none testing "status=noxfer" "dd if=input status=noxfer ibs=1 2>&1" "input\n6+0 records in\n0+1 records out\n" "input\n" "" testing "status=none" "dd if=input status=none ibs=1 2>&1" "input\n" "input\n" "" + +testing "seek stdout" "yes 2> /dev/null | dd bs=8 seek=2 count=1 > out 2> /dev/null && xxd -p out" \ + "00000000000000000000000000000000790a790a790a790a\n" "" "" diff --git a/toys/pending/dd.c b/toys/pending/dd.c index e37f8b28..0c447f74 100644 --- a/toys/pending/dd.c +++ b/toys/pending/dd.c @@ -188,7 +188,7 @@ void dd_main() // seek/truncate as necessary. We handled position zero truncate with // O_TRUNC on open, so output to /dev/null and such doesn't error. - if (TT.out.fd!=1 && (bs = TT.out.offset*TT.out.sz)) { + if ((bs = TT.out.offset*TT.out.sz)) { xlseek(TT.out.fd, bs, SEEK_CUR); if (trunc && ftruncate(TT.out.fd, bs)) perror_exit("ftruncate"); } -- cgit v1.2.3