Changeset 3621 in MondoRescue for branches/3.3/mindi-busybox/libbb/human_readable.c
- Timestamp:
- Dec 20, 2016, 4:07:32 PM (7 years ago)
- Location:
- branches/3.3
- Files:
-
- 1 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/3.3/mindi-busybox/libbb/human_readable.c
r2725 r3621 15 15 * The base ten "bytes" output could be handled similarly. 16 16 * 17 * 2) This routine alwaysoutputs a decimal point and a tenths digit when18 * display_unit != 0. Hence, it isn't uncommon for the returned string17 * 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 19 19 * to have a length of 5 or 6. 20 20 * 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. 27 22 * 28 23 * Licensed under GPLv2, see file LICENSE in this source tree. … … 37 32 '\0', 'K', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y' 38 33 }; 39 40 static char *str;41 34 42 35 unsigned frac; /* 0..9 - the fractional digit */ … … 82 75 } 83 76 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)); 90 78 } 91 79 … … 95 83 /* Convert unsigned long long value into compact 5-char representation. 96 84 * String is not terminated (buf[5] is untouched) */ 97 voidFAST_FUNC smart_ulltoa5(unsigned long long ul, char buf[5], const char *scale)85 char* FAST_FUNC smart_ulltoa5(unsigned long long ul, char buf[5], const char *scale) 98 86 { 99 87 const char *fmt; … … 146 134 buf[4] = scale[idx]; /* typically scale = " kmgt..." */ 147 135 } 136 return buf + 5; 148 137 } 149 138 … … 151 140 * representation. Examples: "1234", "1.2k", " 27M", "123T" 152 141 * String is not terminated (buf[4] is untouched) */ 153 voidFAST_FUNC smart_ulltoa4(unsigned long long ul, char buf[4], const char *scale)142 char* FAST_FUNC smart_ulltoa4(unsigned long long ul, char buf[4], const char *scale) 154 143 { 155 144 const char *fmt; … … 195 184 buf[3] = scale[idx]; /* typically scale = " kmgt..." */ 196 185 } 186 return buf + 4; 197 187 }
Note:
See TracChangeset
for help on using the changeset viewer.