2008-06-15 Pavel Roskin <proski@gnu.org>
* commands/ls.c (grub_ls_list_files): Use integer calculations for human readable format, avoid floating point use. * kern/misc.c (grub_ftoa): Remove. (grub_vsprintf): Remove floating point support.
This commit is contained in:
parent
50465dd603
commit
95614c84f8
3 changed files with 14 additions and 34 deletions
|
@ -108,21 +108,25 @@ grub_ls_list_files (char *dirname, int longlist, int all, int human)
|
|||
grub_printf ("%-12llu", (unsigned long long) file->size);
|
||||
else
|
||||
{
|
||||
float fsize = file->size;
|
||||
grub_uint64_t fsize = file->size * 100ULL;
|
||||
int fsz = file->size;
|
||||
int units = 0;
|
||||
char buf[20];
|
||||
|
||||
while (fsz / 1024)
|
||||
{
|
||||
fsize /= 1024;
|
||||
fsize = (fsize + 512) / 1024;
|
||||
fsz /= 1024;
|
||||
units++;
|
||||
}
|
||||
|
||||
if (units)
|
||||
{
|
||||
grub_sprintf (buf, "%0.2f%c", fsize, grub_human_sizes[units]);
|
||||
grub_uint32_t whole, fraction;
|
||||
|
||||
whole = grub_divmod64 (fsize, 100, &fraction);
|
||||
grub_sprintf (buf, "%u.%02u%c", whole, fraction,
|
||||
grub_human_sizes[units]);
|
||||
grub_printf ("%-12s", buf);
|
||||
}
|
||||
else
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue