summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2002-10-17 15:06:36 +0000
committerJim Meyering <jim@meyering.net>2002-10-17 15:06:36 +0000
commitf72568f82c6b9004a4dc1fbe9dd061d53542c42d (patch)
treea78b2628593c0ec9080f67f409b3ce03ca114f92 /src
parent8c7071d857805a37a3d4c794582f9cbb4009d0b5 (diff)
downloadcoreutils-f72568f82c6b9004a4dc1fbe9dd061d53542c42d.tar.xz
Fix a problem that could make cat misbehave on systems which
give invalid (unreasonably large) values for stat.st_blksize. (ST_BLKSIZE): Ensure that the result is in [1..4MB].
Diffstat (limited to 'src')
-rw-r--r--src/system.h12
1 files changed, 9 insertions, 3 deletions
diff --git a/src/system.h b/src/system.h
index edf242116..594811720 100644
--- a/src/system.h
+++ b/src/system.h
@@ -254,9 +254,15 @@ typedef enum {false = 0, true = 1} bool;
? st_blocks ((statbuf).st_size) : 0)
# endif /* !_POSIX_SOURCE && BSIZE */
#else /* HAVE_STRUCT_STAT_ST_BLOCKS */
-/* Some systems, like Sequents, return st_blksize of 0 on pipes. */
-# define ST_BLKSIZE(statbuf) ((statbuf).st_blksize > 0 \
- ? (statbuf).st_blksize : DEV_BSIZE)
+/* Some systems, like Sequents, return st_blksize of 0 on pipes.
+ Also, when running `cat large-file | rsh hp-ux-system', cat would
+ determine that the output stream had an st_blksize of 2147421096.
+ So here we arbitrarily limit the `optimal' block size to 4MB.
+ If anyone knows of a system for which the legitimate value for
+ st_blksize can exceed 4MB, please report it as a bug in this code. */
+# define ST_BLKSIZE(statbuf) ((0 < (statbuf).st_blksize \
+ && (statbuf).st_blksize <= (1 << 22)) /* 4MB */ \
+ ? (statbuf).st_blksize : DEV_BSIZE)
# if defined hpux || defined __hpux__ || defined __hpux
/* HP-UX counts st_blocks in 1024-byte units.
This loses when mixing HP-UX and BSD filesystems with NFS. */