From: Jim Meyering Date: Fri, 24 Nov 2000 21:18:51 +0000 (+0000) Subject: (main): Use ftruncate only on regular files. X-Git-Tag: FILEUTILS-4_0_33~44 X-Git-Url: http://git.ipfire.org/gitweb/index.cgi?a=commitdiff_plain;h=1d250b6098c11b8bf44d4b6539d89697eff11774;p=thirdparty%2Fcoreutils.git (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. --- diff --git a/src/dd.c b/src/dd.c index 6a4ef9c458..f2c5c36ed5 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