summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2000-11-24 21:18:51 +0000
committerJim Meyering <jim@meyering.net>2000-11-24 21:18:51 +0000
commit1d250b6098c11b8bf44d4b6539d89697eff11774 (patch)
treed5eac66381f16d062d2fedd42806fd14c1ae8529 /src
parentb35b7e0553bab0f93820fdd90a61ff37784f8b1c (diff)
downloadcoreutils-1d250b6098c11b8bf44d4b6539d89697eff11774.tar.xz
(main): Use ftruncate only on regular files.
Based on a patch from Michael Stone. Reported by andras@kolumbus.fi at http://bugs.debian.org/77174.
Diffstat (limited to 'src')
-rw-r--r--src/dd.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/src/dd.c b/src/dd.c
index 6a4ef9c45..f2c5c36ed 100644
--- 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