diff options
author | Chris Sarra <chrissarra@google.com> | 2020-09-15 10:10:20 -0700 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2020-09-23 06:44:05 -0500 |
commit | 204f8c56d69a858eb3455da798c63f6477e1f3b7 (patch) | |
tree | 1ed264d61f7e62c6c13f08a964046dd795fb4ef7 /toys/pending | |
parent | 3c534fdc78e1d9d7914017bfcd5ff579bb754c70 (diff) | |
download | toybox-204f8c56d69a858eb3455da798c63f6477e1f3b7.tar.gz |
Add ftruncate logic to handle non-regular files
ftruncate was failing on device files, leading to whole dd.c failures.
This patch allows us to dump device files.
Diffstat (limited to 'toys/pending')
-rw-r--r-- | toys/pending/dd.c | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/toys/pending/dd.c b/toys/pending/dd.c index 7de91825..a7b7f5fd 100644 --- a/toys/pending/dd.c +++ b/toys/pending/dd.c @@ -224,7 +224,12 @@ void dd_main() if (!(TT.oflag & _DD_oflag_seek_bytes)) bs *= TT.out.sz; if (bs) { xlseek(TT.out.fd, bs, SEEK_CUR); - if (trunc && ftruncate(TT.out.fd, bs)) perror_exit("ftruncate"); + 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"); + } + } } unsigned long long bytes_left = TT.c_count; |