aboutsummaryrefslogtreecommitdiff
path: root/bin/ls
diff options
context:
space:
mode:
authorColin Percival <cperciva@FreeBSD.org>2004-03-01 19:25:27 +0000
committerColin Percival <cperciva@FreeBSD.org>2004-03-01 19:25:27 +0000
commit310924af3d5fc7b2fa6ca0a0f759b7cb3b07188d (patch)
tree7bf1d8fe47a8cb98200950e141f10194494c34ba /bin/ls
parentea753400f0911e7db0ed9669eefb1a35b8785f6c (diff)
downloadsrc-310924af3d5fc7b2fa6ca0a0f759b7cb3b07188d.tar.gz
src-310924af3d5fc7b2fa6ca0a0f759b7cb3b07188d.zip
Fixes to output of `ls -lh` for certain file sizes:
1. Sizes in the range 1000 -- 1023 units require four characters width for the integer; increase the field width to accomodate this. 2. Sizes in the range 9.95 -- 10 units were being displayed as "10.0" units; adjust the logic to fix this, and now that we've got an extra character of field width, print fractional units if the size is less than 99.95 units. 3. Don't display sub-byte precision. This should mean that the following sizes are displayed: 0B .. 1023B 1.0U .. 9.9U 10.0U .. 99.9U 100U .. 1023U for values of U in "KMGTPE". PR: bin/63547 Pointy hat to: cperciva Approved by: rwatson (mentor)
Notes
Notes: svn path=/head/; revision=126458
Diffstat (limited to 'bin/ls')
-rw-r--r--bin/ls/print.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/bin/ls/print.c b/bin/ls/print.c
index 10a19d9e1330..d4cae67198c4 100644
--- a/bin/ls/print.c
+++ b/bin/ls/print.c
@@ -623,11 +623,11 @@ printsize(size_t width, off_t bytes)
dbytes = bytes;
unit = unit_adjust(&dbytes);
- if (dbytes == 0)
- (void)printf("%*s ", 4, "0B");
+ if (unit == 0)
+ (void)printf("%*d%c ", 4, (int)bytes, 'B');
else
- (void)printf("%*.*f%c ", 3,
- dbytes > 10 ? 0 : 1, dbytes, "BKMGTPE"[unit]);
+ (void)printf("%*.*f%c ", 4,
+ dbytes >= 99.95 ? 0 : 1, dbytes, "BKMGTPE"[unit]);
} else
(void)printf("%*jd ", (u_int)width, bytes);
}