summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>1997-11-30 10:24:20 +0000
committerJim Meyering <jim@meyering.net>1997-11-30 10:24:20 +0000
commitf633782aa195bfffd88950f73135db26297bff2e (patch)
tree7ffae2188b59852e4f71555b57a2d4b2f0a1b07a /lib
parentce43e130bb2ff34a8020061db7a9339061810530 (diff)
downloadcoreutils-f633782aa195bfffd88950f73135db26297bff2e.tar.xz
(st_blocks): long -> off_t.
Avoid arithmetic overflow when size is near max. Depend on _POSIX_SOURCE and BSIZE, not _POSIX_VERSION, for compatibility with system.h. (BSIZE): Remove definition, since if BSIZE is not defined we're never invoked.
Diffstat (limited to 'lib')
-rw-r--r--lib/fileblocks.c17
1 files changed, 6 insertions, 11 deletions
diff --git a/lib/fileblocks.c b/lib/fileblocks.c
index 7f696ab2f..6a421cf51 100644
--- a/lib/fileblocks.c
+++ b/lib/fileblocks.c
@@ -21,7 +21,7 @@
# include <config.h>
#endif
-#if !defined (HAVE_ST_BLOCKS) && !defined(_POSIX_VERSION)
+#if !HAVE_ST_BLOCKS && !defined _POSIX_SOURCE && defined BSIZE
# include <sys/types.h>
# include <sys/param.h>
@@ -30,12 +30,7 @@
# endif
# ifndef NINDIR
-/* Some SysV's, like Irix, seem to lack these. Hope they're correct. */
-/* Size of a indirect block, in bytes. */
-# ifndef BSIZE
-# define BSIZE 1024
-# endif
-
+/* Some SysV's, like Irix, seem to lack this. Hope it's correct. */
/* Number of inode pointers per indirect block. */
# define NINDIR (BSIZE/sizeof(daddr_t))
# endif /* !NINDIR */
@@ -45,12 +40,12 @@
/* Return the number of 512-byte blocks in a file of SIZE bytes. */
-long
+off_t
st_blocks (size)
- long size;
+ off_t size;
{
- long datablks = (size + 512 - 1) / 512;
- long indrblks = 0;
+ off_t datablks = size / 512 + (size % 512 != 0);
+ off_t indrblks = 0;
if (datablks > NDIR)
{