]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
(main): Use ftruncate only on regular files.
authorJim Meyering <jim@meyering.net>
Fri, 24 Nov 2000 21:18:51 +0000 (21:18 +0000)
committerJim Meyering <jim@meyering.net>
Fri, 24 Nov 2000 21:18:51 +0000 (21:18 +0000)
Based on a patch from Michael Stone.
Reported by andras@kolumbus.fi at http://bugs.debian.org/77174.

src/dd.c

index 6a4ef9c45849a024c298b27f1aca970e72c05bb7..f2c5c36ed5018030252a6fdaa2cedb1bd9228104 100644 (file)
--- a/src/dd.c
+++ b/src/dd.c
@@ -1150,15 +1150,21 @@ main (int argc, char **argv)
 #if HAVE_FTRUNCATE
       if (seek_record != 0 && !(conversions_mask & C_NOTRUNC))
        {
+         struct stat stdout_stat;
          off_t o = seek_record * output_blocksize;
          if (o / output_blocksize != seek_record)
            error (1, 0, _("file offset out of range"));
-         if (ftruncate (STDOUT_FILENO, o) < 0)
+
+         /* Attempt to use ftruncate only if STDOUT refers to a regular file.
+            On Linux 2.4.0, ftruncate fails with for non-regular files.  */
+         if (fstat (STDOUT_FILENO, &stdout_stat) == 0
+             && S_ISREG (stdout_stat.st_mode)
+             && ftruncate (STDOUT_FILENO, o) < 0)
            {
              char buf[LONGEST_HUMAN_READABLE + 1];
              error (1, errno, _("advancing past %s blocks in output file %s"),
-                                human_readable (seek_record, buf, 1, 1),
-                                quote (output_file));
+                    human_readable (seek_record, buf, 1, 1),
+                    quote (output_file));
            }
        }
 #endif