du -m is off

"Jeremy C. Reed" <[email protected]>
Newsgroups gmane.os.netbsd.devel.general
Message-ID <[email protected]>
I noticed that a file of 10485760 bytes would be listed as 11MB by du -m. 
The -h "humanize" is correct and lists as 10MB.

du.c uses:

                (void)printf("%lld\t%s\n",
                    (long long)howmany(blocks, (int64_t)blocksize),

This works better for me:

printf("%ld\n", (long)((int64_t)blocks / blocksize));

But that doesn't help for files less than a megabyte which will then be 
displayed as a zero.

As another example, a file of 3372684 bytes is 3.21644MB. du -m would 
round up to 4. While my printf above prints "3".

I am not sure what correct behaviour should be.

Either way, the du man page should document about this as it is 
misleading.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.