Skip to content

Commit b305452

Browse files
rmccGerrit Code Review
authored and
Gerrit Code Review
committed
Merge "Fixed improper size displaying in 'df' utility" into jellybean
2 parents 283b70b + d7e08dc commit b305452

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

toolbox/df.c

+16-5
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,27 @@ static int ok = EXIT_SUCCESS;
99
static void printsize(long long n)
1010
{
1111
char unit = 'K';
12-
n /= 1024;
13-
if (n > 1024) {
12+
long long t;
13+
14+
n *= 10;
15+
16+
if (n > 1024*1024*10) {
1417
n /= 1024;
1518
unit = 'M';
1619
}
17-
if (n > 1024) {
20+
21+
if (n > 1024*1024*10) {
1822
n /= 1024;
1923
unit = 'G';
2024
}
21-
printf("%4lld%c", n, unit);
25+
26+
t = (n + 512) / 1024;
27+
if (t%10 != 0) {
28+
printf("%4lld.%1lld%c", t/10, t%10, unit);
29+
}
30+
else {
31+
printf("%4lld%c", t/10, unit);
32+
}
2233
}
2334

2435
static void df(char *s, int always) {
@@ -41,7 +52,7 @@ static void df(char *s, int always) {
4152
}
4253

4354
int df_main(int argc, char *argv[]) {
44-
printf("Filesystem Size Used Free Blksize\n");
55+
printf("Filesystem Size Used Free Blksize\n");
4556
if (argc == 1) {
4657
char s[2000];
4758
FILE *f = fopen("/proc/mounts", "r");

0 commit comments

Comments
 (0)