From: James Youngman Date: Fri, 17 Jul 2026 11:55:29 +0000 (+0100) Subject: gendocs: correct the calculation of file sizes. X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=b5835d75e49efbad76806db337bd04420f0203ae;p=thirdparty%2Fgnulib.git gendocs: correct the calculation of file sizes. * build-aux/gendocs.sh (calcsize): do not assume "ls -sk" tells us the size of the file in KiB. Calculate it from the file length instead. --- diff --git a/build-aux/gendocs.sh b/build-aux/gendocs.sh index 80b0a17368..2b3373ecf7 100755 --- a/build-aux/gendocs.sh +++ b/build-aux/gendocs.sh @@ -2,7 +2,7 @@ # gendocs.sh -- generate a GNU manual in many formats. This script is # mentioned in maintain.texi. See the help message below for usage details. -scriptversion=2026-01-01.00 +scriptversion=2026-07-17.13 # Copyright 2003-2026 Free Software Foundation, Inc. # @@ -230,10 +230,24 @@ if test ! -r $GENDOCS_TEMPLATE_DIR/gendocs_template; then fi # Function to return size of $1 in something resembling kilobytes. +# We don't use `ls -s` because that can be longer or shorter than +# the real length of the data (because the file system compresses +# the file, for example). We don't use `du -k --apparent-size` +# because we do not want to assume `du` supports that option. +# +# Here's an example of different `ls -s` results on different file +# systems: +# +# $ cp /var/tmp/findutils-manual/find.html find.html +# $ ls -lsh /var/tmp/findutils-manual/find.html find.html +# 221K -rw-rw-r-- 1 james james 582K Jul 17 13:01 find.html +# 584K -rw-rw-r-- 1 james james 582K Jul 17 12:54 /var/tmp/findutils-manual/find.html calcsize() { - set `ls -ks "$1"` - echo $1 + # Determine size in bytes + set `env LC_ALL=C wc -c < "$1"` + # Emit the size in KiB, rounding up. + expr '(' "$1" + 1023 ')' / 1024 } # copy_images OUTDIR HTML-FILE...