* fileutils/dd.c (dd_main): Ignore ftruncate error if the output is not a
authorMatt Kraai <kraai@debian.org>
Tue, 5 Feb 2002 15:28:54 +0000 (15:28 -0000)
committerMatt Kraai <kraai@debian.org>
Tue, 5 Feb 2002 15:28:54 +0000 (15:28 -0000)
  file or directory.

coreutils/dd.c

index 818ab777e9a99dabb2b604825be403fa300e8ab4..09e6cccc72ff9c7be988acc4d5869fc5e16aac55 100644 (file)
@@ -22,6 +22,7 @@
  */
 
 #include <sys/types.h>
+#include <sys/stat.h>
 #include <stdlib.h>
 #include <stdio.h>
 #include <unistd.h>
@@ -106,8 +107,13 @@ int dd_main(int argc, char **argv)
                        perror_msg_and_die("%s", outfile);
 
                if (seek && trunc) {
-                       if (ftruncate(ofd, seek * bs) < 0)
-                               perror_msg_and_die("%s", outfile);
+                       if (ftruncate(ofd, seek * bs) < 0) {
+                               struct stat st;
+
+                               if (fstat (ofd, &st) < 0 || S_ISREG (st.st_mode) ||
+                                               S_ISDIR (st.st_mode))
+                                       perror_msg_and_die("%s", outfile);
+                       }
                }
        } else {
                ofd = STDOUT_FILENO;