Ignore:
Timestamp:
Dec 20, 2016, 4:07:32 PM (7 years ago)
Author:
Bruno Cornec
Message:

New 3?3 banch for incorporation of latest busybox 1.25. Changing minor version to handle potential incompatibilities.

Location:
branches/3.3
Files:
1 edited
1 copied

Legend:

Unmodified
Added
Removed
  • branches/3.3/mindi-busybox/libbb/human_readable.c

    r2725 r3621  
    1515 *      The base ten "bytes" output could be handled similarly.
    1616 *
    17  *   2) This routine always outputs a decimal point and a tenths digit when
    18  *      display_unit != 0.  Hence, it isn't uncommon for the returned string
     17 *   2) This routine outputs a decimal point and a tenths digit when
     18 *      display_unit == 0.  Hence, it isn't uncommon for the returned string
    1919 *      to have a length of 5 or 6.
    2020 *
    21  *      It might be nice to add a flag to indicate no decimal digits in
    22  *      that case.  This could be either an additional parameter, or a
    23  *      special value of display_unit.  Such a flag would also be nice for du.
    24  *
    25  *      Some code to omit the decimal point and tenths digit is sketched out
    26  *      and "#if 0"'d below.
     21 *      If block_size is also 0, no decimal digits are printed.
    2722 *
    2823 * Licensed under GPLv2, see file LICENSE in this source tree.
     
    3732        '\0', 'K', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y'
    3833    };
    39 
    40     static char *str;
    4134
    4235    unsigned frac; /* 0..9 - the fractional digit */
     
    8275    }
    8376
    84     if (!str) {
    85         /* sufficient for any width of val */
    86         str = xmalloc(sizeof(val)*3 + 2 + 3);
    87     }
    88     sprintf(str, fmt, val, frac, *u);
    89     return str;
     77    return auto_string(xasprintf(fmt, val, frac, *u));
    9078}
    9179
     
    9583/* Convert unsigned long long value into compact 5-char representation.
    9684 * String is not terminated (buf[5] is untouched) */
    97 void FAST_FUNC smart_ulltoa5(unsigned long long ul, char buf[5], const char *scale)
     85char* FAST_FUNC smart_ulltoa5(unsigned long long ul, char buf[5], const char *scale)
    9886{
    9987    const char *fmt;
     
    146134        buf[4] = scale[idx]; /* typically scale = " kmgt..." */
    147135    }
     136    return buf + 5;
    148137}
    149138
     
    151140 * representation. Examples: "1234", "1.2k", " 27M", "123T"
    152141 * String is not terminated (buf[4] is untouched) */
    153 void FAST_FUNC smart_ulltoa4(unsigned long long ul, char buf[4], const char *scale)
     142char* FAST_FUNC smart_ulltoa4(unsigned long long ul, char buf[4], const char *scale)
    154143{
    155144    const char *fmt;
     
    195184        buf[3] = scale[idx]; /* typically scale = " kmgt..." */
    196185    }
     186    return buf + 4;
    197187}
Note: See TracChangeset for help on using the changeset viewer.