Commit 5562b59e authored by Leah Neukirchen's avatar Leah Neukirchen

print file size in groups of three digits when -G is used

We use a custom printing function as %'jd is locale-dependent (and not
implemented in musl).
parent 8191e3d5
......@@ -2,6 +2,7 @@
* Feature: new option `-P` to quote filenames with `$'...'` syntax.
* Feature: invalid UTF-8 filenames are quoted now.
* Feature: colorized file size output now uses groups of three digits.
## 1.2 (2017-11-17)
......
......@@ -1631,6 +1631,23 @@ color_size_on(off_t s)
fg256(c);
}
static void
print_comma(int len, intmax_t i)
{
char buf[64];
char *s = buf + sizeof buf;
*--s = 0;
while (1) {
*--s = (i % 10) + '0'; if ((i /= 10) <= 0) break;
*--s = (i % 10) + '0'; if ((i /= 10) <= 0) break;
*--s = (i % 10) + '0'; if ((i /= 10) <= 0) break;
*--s = ',';
}
printf("%*.*s", len+len/3, len+len/3, s);
}
static void
print_human(intmax_t i)
{
......@@ -1956,8 +1973,12 @@ print_format(struct fileinfo *fi)
case 's':
if (!hflag) {
color_size_on(fi->sb.st_size);
printf("%*jd", intlen(maxsize),
(intmax_t)fi->sb.st_size);
if (Gflag)
print_comma(intlen(maxsize),
(intmax_t)fi->sb.st_size);
else
printf("%*jd", intlen(maxsize),
(intmax_t)fi->sb.st_size);
fgdefault();
break;
}
......
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