~ubuntu-branches/ubuntu/trusty/drbd8/trusty

« back to all changes in this revision

Viewing changes to user/drbdtool_common.c

  • Committer: Bazaar Package Importer
  • Author(s): Andres Rodriguez
  • Date: 2011-07-05 15:40:13 UTC
  • mfrom: (1.4.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20110705154013-f9l32owj6mi9e1p0
Tags: 2:8.3.11-0ubuntu1
* New upstream release
* debian/patches/01_ubuntu_cn_idx.dpatch: Refreshed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
45
45
}
46
46
 
47
47
 
48
 
char* ppsize(char* buf, size_t size)
 
48
/* input size is expected to be in KB */
 
49
char *ppsize(char *buf, unsigned long long size)
49
50
{
50
 
        // Needs 9 bytes at max.
51
 
        static char units[] = { 'K','M','G','T' };
 
51
        /* Needs 9 bytes at max including trailing NUL:
 
52
         * -1ULL ==> "16384 EB" */
 
53
        static char units[] = { 'K', 'M', 'G', 'T', 'P', 'E' };
52
54
        int base = 0;
53
 
        while (size >= 10000 ) {
54
 
                size = size >> 10;
 
55
        while (size >= 10000 && base < sizeof(units)-1) {
 
56
                /* shift + round */
 
57
                size = (size >> 10) + !!(size & (1<<9));
55
58
                base++;
56
59
        }
57
 
        sprintf(buf,"%lu %cB",(unsigned long)size,units[base]);
 
60
        sprintf(buf, "%u %cB", (unsigned)size, units[base]);
58
61
 
59
62
        return buf;
60
63
}