Place a temporary bandaid on the ls/du/df human-readable issue. This method is
not going to scale up as well as I would like, and Matt Kraai and I have discussed a better long term solution. But for now this will at least make all the human-readable apps give correct answers. Please test the human readable/non-human readable options on your systems!!! -Erik
This commit is contained in:
parent
24073c7665
commit
91c9388715
@ -648,15 +648,18 @@ static int list_single(struct dnode *dn)
|
|||||||
printf("%4d, %3d ", (int)MAJOR(dn->dstat.st_rdev), (int)MINOR(dn->dstat.st_rdev));
|
printf("%4d, %3d ", (int)MAJOR(dn->dstat.st_rdev), (int)MINOR(dn->dstat.st_rdev));
|
||||||
} else {
|
} else {
|
||||||
#ifdef BB_FEATURE_HUMAN_READABLE
|
#ifdef BB_FEATURE_HUMAN_READABLE
|
||||||
fprintf(stdout, "%9s ", make_human_readable_str(dn->dstat.st_size>>10,
|
if (ls_disp_hr==TRUE) {
|
||||||
(ls_disp_hr==TRUE)? 0: 1));
|
fprintf(stdout, "%9s ", make_human_readable_str(
|
||||||
#else
|
dn->dstat.st_size>>10, 0));
|
||||||
|
} else
|
||||||
|
#endif
|
||||||
|
{
|
||||||
#if _FILE_OFFSET_BITS == 64
|
#if _FILE_OFFSET_BITS == 64
|
||||||
printf("%9lld ", dn->dstat.st_size);
|
printf("%9lld ", dn->dstat.st_size);
|
||||||
#else
|
#else
|
||||||
printf("%9ld ", dn->dstat.st_size);
|
printf("%9ld ", dn->dstat.st_size);
|
||||||
#endif
|
#endif
|
||||||
#endif
|
}
|
||||||
}
|
}
|
||||||
column += 10;
|
column += 10;
|
||||||
break;
|
break;
|
||||||
|
@ -28,26 +28,35 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "libbb.h"
|
#include "libbb.h"
|
||||||
|
|
||||||
static char buffer[10];
|
|
||||||
static const char *suffixes[] = { "", "k", "M", "G", "T" };
|
|
||||||
|
|
||||||
const char *make_human_readable_str(unsigned long val, unsigned long not_hr)
|
|
||||||
|
const char *make_human_readable_str(unsigned long val, unsigned long hr)
|
||||||
{
|
{
|
||||||
int suffix, base;
|
int i=0;
|
||||||
|
static char str[10] = "\0";
|
||||||
|
static const char strings[] = { 'k', 'M', 'G', 'T', 0 };
|
||||||
|
unsigned long divisor = 1;
|
||||||
|
|
||||||
if (not_hr)
|
if(val == 0)
|
||||||
sprintf(buffer, "%lu", val);
|
return("0");
|
||||||
else
|
if(hr)
|
||||||
for (suffix = 0, base = 1; suffix < 5; suffix++, base <<= 10) {
|
snprintf(str, 9, "%ld", val/hr);
|
||||||
if (val < (base << 10)) {
|
else {
|
||||||
if (suffix && val < 10 * base)
|
while(val >= divisor && i <= 4) {
|
||||||
sprintf(buffer, "%lu.%lu%s", val / base,
|
divisor=divisor<<10, i++;
|
||||||
(val % base) * 10 / base, suffixes[suffix]);
|
|
||||||
else
|
|
||||||
sprintf(buffer, "%lu%s", val / base, suffixes[suffix]);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
divisor=divisor>>10, i--;
|
||||||
|
snprintf(str, 9, "%.1Lf%c", (long double)(val)/divisor, strings[i]);
|
||||||
|
}
|
||||||
|
return(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
return buffer;
|
|
||||||
}
|
/* END CODE */
|
||||||
|
/*
|
||||||
|
Local Variables:
|
||||||
|
c-file-style: "linux"
|
||||||
|
c-basic-offset: 4
|
||||||
|
tab-width: 4
|
||||||
|
End:
|
||||||
|
*/
|
||||||
|
11
ls.c
11
ls.c
@ -648,15 +648,18 @@ static int list_single(struct dnode *dn)
|
|||||||
printf("%4d, %3d ", (int)MAJOR(dn->dstat.st_rdev), (int)MINOR(dn->dstat.st_rdev));
|
printf("%4d, %3d ", (int)MAJOR(dn->dstat.st_rdev), (int)MINOR(dn->dstat.st_rdev));
|
||||||
} else {
|
} else {
|
||||||
#ifdef BB_FEATURE_HUMAN_READABLE
|
#ifdef BB_FEATURE_HUMAN_READABLE
|
||||||
fprintf(stdout, "%9s ", make_human_readable_str(dn->dstat.st_size>>10,
|
if (ls_disp_hr==TRUE) {
|
||||||
(ls_disp_hr==TRUE)? 0: 1));
|
fprintf(stdout, "%9s ", make_human_readable_str(
|
||||||
#else
|
dn->dstat.st_size>>10, 0));
|
||||||
|
} else
|
||||||
|
#endif
|
||||||
|
{
|
||||||
#if _FILE_OFFSET_BITS == 64
|
#if _FILE_OFFSET_BITS == 64
|
||||||
printf("%9lld ", dn->dstat.st_size);
|
printf("%9lld ", dn->dstat.st_size);
|
||||||
#else
|
#else
|
||||||
printf("%9ld ", dn->dstat.st_size);
|
printf("%9ld ", dn->dstat.st_size);
|
||||||
#endif
|
#endif
|
||||||
#endif
|
}
|
||||||
}
|
}
|
||||||
column += 10;
|
column += 10;
|
||||||
break;
|
break;
|
||||||
|
Loading…
Reference in New Issue
Block a user