Commit c108d8ec authored by Paul Eggert's avatar Paul Eggert

Don’t round file-system-info counts

* src/fileio.c (blocks_to_bytes): Convert the byte count to an
integer, since we have bignums now.  This avoids possible rounding
errors for file systems containing more than 8 PiB or so.
parent d27fb533
Pipeline #3174 failed with stage
in 77 minutes and 38 seconds
...@@ -6081,16 +6081,18 @@ effect except for flushing STREAM's data. */) ...@@ -6081,16 +6081,18 @@ effect except for flushing STREAM's data. */)
#ifndef DOS_NT #ifndef DOS_NT
/* Yield a Lisp float as close as possible to BLOCKSIZE * BLOCKS, with /* Yield a Lisp number equal to BLOCKSIZE * BLOCKS, with the result
the result negated if NEGATE. */ negated if NEGATE. */
static Lisp_Object static Lisp_Object
blocks_to_bytes (uintmax_t blocksize, uintmax_t blocks, bool negate) blocks_to_bytes (uintmax_t blocksize, uintmax_t blocks, bool negate)
{ {
/* On typical platforms the following code is accurate to 53 bits, intmax_t n;
which is close enough. BLOCKSIZE is invariably a power of 2, so if (!INT_MULTIPLY_WRAPV (blocksize, blocks, &n))
converting it to double does not lose information. */ return make_int (negate ? -n : n);
double bs = blocksize; Lisp_Object bs = make_uint (blocksize);
return make_float (negate ? -bs * -blocks : bs * blocks); if (negate)
bs = CALLN (Fminus, bs);
return CALLN (Ftimes, bs, make_uint (blocks));
} }
DEFUN ("file-system-info", Ffile_system_info, Sfile_system_info, 1, 1, 0, DEFUN ("file-system-info", Ffile_system_info, Sfile_system_info, 1, 1, 0,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment