Handle ftruncate(2) errors in dd(1)
---
bin/dd/dd.c | 5 ++++-
bin/dd/dd.h | 3 ++-
2 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/bin/dd/dd.c b/bin/dd/dd.c
index d07d935bde7..4b0d99144e2 100644
--- a/bin/dd/dd.c
+++ b/bin/dd/dd.c
@@ -161,7 +161,8 @@ setup(void)
* kinds of output files, tapes, for example.
*/
if ((ddflags & (C_OF | C_SEEK | C_NOTRUNC)) == (C_OF | C_SEEK))
- (void)ftruncate(out.fd, out.offset * out.dbsz);
+ if (ftruncate(out.fd, out.offset * out.dbsz) && (out.flags &
ISREG))
+ err(1, "%s", out.name);
/*
* If converting case at the same time as another conversion, build a
@@ -212,6 +213,8 @@ getfdtype(IO *io)
io->flags |= ioctl(io->fd, MTIOCGET, &mt) ? ISCHR : ISTAPE;
if (S_ISFIFO(sb.st_mode) || S_ISSOCK(sb.st_mode))
io->flags |= ISPIPE;
+ if (S_ISREG(sb.st_mode))
+ io->flags |= ISREG;
}
static void
diff --git a/bin/dd/dd.h b/bin/dd/dd.h
index 487cd0c9e97..8b6fb969467 100644
--- a/bin/dd/dd.h
+++ b/bin/dd/dd.h
@@ -47,7 +47,8 @@ typedef struct {
#define ISCHR 0x01 /* character device (warn on
short) */
#define ISPIPE 0x02 /* pipe (not truncatable) */
#define ISTAPE 0x04 /* tape (not seekable) */
-#define NOREAD 0x08 /* not readable */
+#define ISREG 0x08 /* regular file (warn on
truncation errors) */
+#define NOREAD 0x10 /* not readable */
u_int flags;
char *name; /* name */
--
2.44.0