diff options
-rw-r--r-- | toys/pending/dd.c | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/toys/pending/dd.c b/toys/pending/dd.c index a7b7f5fd..8f4e711e 100644 --- a/toys/pending/dd.c +++ b/toys/pending/dd.c @@ -223,13 +223,11 @@ void dd_main() bs = TT.out.offset; if (!(TT.oflag & _DD_oflag_seek_bytes)) bs *= TT.out.sz; if (bs) { + struct stat st; + xlseek(TT.out.fd, bs, SEEK_CUR); - if (trunc && ftruncate(TT.out.fd, bs)) { - struct stat st; - if (fstat(TT.out.fd, &st) < 0 || S_ISREG(st.st_mode) || S_ISDIR(st.st_mode)) { - perror_exit("unexpected ftruncate failure"); - } - } + if (trunc && !fstat(TT.out.fd, &st) && S_ISREG(st.st_mode) + && ftruncate(TT.out.fd, bs)) perror_exit("unexpected ftruncate failure"); } unsigned long long bytes_left = TT.c_count; |