Changeset 1770 in MondoRescue for branches/stable/mindi-busybox/libbb/human_readable.c
- Timestamp:
- Nov 6, 2007, 11:01:53 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/stable/mindi-busybox/libbb/human_readable.c
r821 r1770 1 /* vi: set sw=4 ts=4: */ 1 2 /* 2 3 * June 30, 2001 Manuel Novoa III … … 26 27 */ 27 28 28 #include <stdio.h>29 29 #include "libbb.h" 30 30 … … 32 32 unsigned long block_size, unsigned long display_unit) 33 33 { 34 /* The code will adjust for additional (appended) units .*/35 static const char zero_and_units[] = { '0', 0, 'k', 'M', 'G', 'T' };36 static const char fmt[] = "%llu";37 static const char fmt_tenths[] = "%llu.%d%c";34 /* The code will adjust for additional (appended) units */ 35 static const char zero_and_units[] ALIGN1 = { '0', 0, 'k', 'M', 'G', 'T' }; 36 static const char fmt[] ALIGN1 = "%llu"; 37 static const char fmt_tenths[] ALIGN1 = "%llu.%d%c"; 38 38 39 static char str[21] ; /* Sufficient for 64 bit unsigned integers.*/39 static char str[21] ALIGN1; /* Sufficient for 64 bit unsigned integers */ 40 40 41 41 unsigned long long val; … … 54 54 55 55 if (display_unit) { 56 val += display_unit/2; /* Deal with rounding .*/56 val += display_unit/2; /* Deal with rounding */ 57 57 val /= display_unit; /* Don't combine with the line above!!! */ 58 58 } else { 59 59 ++u; 60 while ((val >= KILOBYTE) 61 && (u < zero_and_units + sizeof(zero_and_units) - 1)) { 60 while ((val >= 1024) 61 && (u < zero_and_units + sizeof(zero_and_units) - 1) 62 ) { 62 63 f = fmt_tenths; 63 64 ++u; 64 frac = ((( (int)(val % KILOBYTE)) * 10) + (KILOBYTE/2)) / KILOBYTE;65 val /= KILOBYTE;65 frac = (((int)(val % 1024)) * 10 + 1024/2) / 1024; 66 val /= 1024; 66 67 } 67 68 if (frac >= 10) { /* We need to round up here. */ … … 71 72 #if 0 72 73 /* Sample code to omit decimal point and tenths digit. */ 73 if ( /* no_tenths */ 1) {74 if ( frac >= 5) {74 if (/* no_tenths */ 1) { 75 if (frac >= 5) { 75 76 ++val; 76 77 } 77 f = "%llu%*c" /* fmt_no_tenths */ 78 f = "%llu%*c" /* fmt_no_tenths */; 78 79 frac = 1; 79 80 }
Note:
See TracChangeset
for help on using the changeset viewer.