aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2020-09-23 06:50:39 -0500
committerRob Landley <rob@landley.net>2020-09-23 06:50:39 -0500
commit9cce74afd2561663bceab9a5ce609109b18aca57 (patch)
tree3873147623c8f347dee652dc2cb6103fe0bc539e
parent204f8c56d69a858eb3455da798c63f6477e1f3b7 (diff)
downloadtoybox-9cce74afd2561663bceab9a5ce609109b18aca57.tar.gz
Only attempt to truncate regular files in dd.
-rw-r--r--toys/pending/dd.c10
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;