On Thu, Nov 15, 2018 at 1:49 AM Tetsuo Handa <
[email protected]> wrote:
> 32bits userspace on 64bits kernel:
> # truncate -s 9223372036854775807 test
> # perl -e 'use File::stat; my $sb = lstat("test"); printf("%s\n",
$sb->size);'
> 9.22337203685478e+18
> # perl -e 'use File::stat; my $sb = lstat("test"); printf("%u\n",
$sb->size);'
> 4294967295
Note that "%s" is providing an inaccurate (rounded) result.
Doing :
"%s\n", $sb->size
will provide correct results if the file size is less than or equal
to 1e+15 bytes but, for larger sizes, the value that is output is subject
to rounding.
Doing :
"%.15e\n", $sb->size
provides an improvement on "%s" in that, for files up to
9.007199254740992e+015 bytes, it will provide a correct figure:
If you're encountering files larger than 9.007199254740992e+015 bytes, the
best solution is to simply build perl with -Duse64bitint, though building
with -Duselongdouble would probably also address this issue by providing a
64-bit precision NV.
I do, of course, understand that such solutions might be inapplicable
regarding your situation.
Are you actually encountering files larger than 1e15 bytes ?
If not, then either:
printf("%s\n", $sb->size);
or
printf("%.15e\n", $sb->size;
or
print $sb->size;
should be fine.
Cheers,
Rob