Changeset 11 for trunk/gtk/util.c


Ignore:
Timestamp:
Jan 12, 2006, 6:47:30 PM (17 years ago)
Author:
root
Message:

Update 2005-12-04

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gtk/util.c

    r7 r11  
    5454
    5555  return FALSE;
     56}
     57
     58char *
     59readablesize(guint64 size, int decimals) {
     60  const char *sizes[] = {"B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB"};
     61  unsigned int ii;
     62  double small = size;
     63
     64  for(ii = 0; ii + 1 < ALEN(sizes) && 1024.0 <= small / 1024.0; ii++)
     65    small /= 1024.0;
     66
     67  if(1024.0 <= small) {
     68    small /= 1024.0;
     69    ii++;
     70  }
     71
     72  return g_strdup_printf("%.*f %s", decimals, small, sizes[ii]);
    5673}
    5774
Note: See TracChangeset for help on using the changeset viewer.