| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/coreutils/src/gnulib/lib/human.c |
| Switch to Source code | Preprocessed file |
| Line | Source | Count | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | - | |||||||||||||||||||||||||
| 2 | - | |||||||||||||||||||||||||
| 3 | - | |||||||||||||||||||||||||
| 4 | - | |||||||||||||||||||||||||
| 5 | - | |||||||||||||||||||||||||
| 6 | - | |||||||||||||||||||||||||
| 7 | - | |||||||||||||||||||||||||
| 8 | static const char power_letter[] = | - | ||||||||||||||||||||||||
| 9 | { | - | ||||||||||||||||||||||||
| 10 | 0, | - | ||||||||||||||||||||||||
| 11 | 'K', | - | ||||||||||||||||||||||||
| 12 | 'M', | - | ||||||||||||||||||||||||
| 13 | 'G', | - | ||||||||||||||||||||||||
| 14 | 'T', | - | ||||||||||||||||||||||||
| 15 | 'P', | - | ||||||||||||||||||||||||
| 16 | 'E', | - | ||||||||||||||||||||||||
| 17 | 'Z', | - | ||||||||||||||||||||||||
| 18 | 'Y' | - | ||||||||||||||||||||||||
| 19 | }; | - | ||||||||||||||||||||||||
| 20 | - | |||||||||||||||||||||||||
| 21 | - | |||||||||||||||||||||||||
| 22 | - | |||||||||||||||||||||||||
| 23 | - | |||||||||||||||||||||||||
| 24 | - | |||||||||||||||||||||||||
| 25 | static long double | - | ||||||||||||||||||||||||
| 26 | adjust_value (int inexact_style, long double value) | - | ||||||||||||||||||||||||
| 27 | { | - | ||||||||||||||||||||||||
| 28 | - | |||||||||||||||||||||||||
| 29 | - | |||||||||||||||||||||||||
| 30 | - | |||||||||||||||||||||||||
| 31 | - | |||||||||||||||||||||||||
| 32 | if (inexact_style != human_round_to_nearest
| 0-220 | ||||||||||||||||||||||||
| 33 | (18446744073709551615UL)
| 0 | ||||||||||||||||||||||||
| 34 | ) | - | ||||||||||||||||||||||||
| 35 | { | - | ||||||||||||||||||||||||
| 36 | uintmax_t u = value; | - | ||||||||||||||||||||||||
| 37 | value = u + (inexact_style == human_ceiling
| 0 | ||||||||||||||||||||||||
| 38 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 39 | - | |||||||||||||||||||||||||
| 40 | return executed 220 times by 1 test: value;return value;Executed by:
executed 220 times by 1 test: return value;Executed by:
| 220 | ||||||||||||||||||||||||
| 41 | } | - | ||||||||||||||||||||||||
| 42 | static char * | - | ||||||||||||||||||||||||
| 43 | group_number (char *number, size_t numberlen, | - | ||||||||||||||||||||||||
| 44 | char const *grouping, char const *thousands_sep) | - | ||||||||||||||||||||||||
| 45 | { | - | ||||||||||||||||||||||||
| 46 | register char *d; | - | ||||||||||||||||||||||||
| 47 | size_t grouplen = | - | ||||||||||||||||||||||||
| 48 | (18446744073709551615UL) | - | ||||||||||||||||||||||||
| 49 | ; | - | ||||||||||||||||||||||||
| 50 | size_t thousands_seplen = strlen (thousands_sep); | - | ||||||||||||||||||||||||
| 51 | size_t i = numberlen; | - | ||||||||||||||||||||||||
| 52 | - | |||||||||||||||||||||||||
| 53 | - | |||||||||||||||||||||||||
| 54 | - | |||||||||||||||||||||||||
| 55 | char buf[2 * (((((sizeof (uintmax_t) * 8) - (! ((__typeof__ (uintmax_t)) 0 < (__typeof__ (uintmax_t)) -1))) * 146 + 484) / 485) + (! ((__typeof__ (uintmax_t)) 0 < (__typeof__ (uintmax_t)) -1))) + 1]; | - | ||||||||||||||||||||||||
| 56 | - | |||||||||||||||||||||||||
| 57 | memcpy (buf, number, numberlen); | - | ||||||||||||||||||||||||
| 58 | d = number + numberlen; | - | ||||||||||||||||||||||||
| 59 | - | |||||||||||||||||||||||||
| 60 | for (;;) | - | ||||||||||||||||||||||||
| 61 | { | - | ||||||||||||||||||||||||
| 62 | unsigned char g = *grouping; | - | ||||||||||||||||||||||||
| 63 | - | |||||||||||||||||||||||||
| 64 | if (g
| 0 | ||||||||||||||||||||||||
| 65 | { | - | ||||||||||||||||||||||||
| 66 | grouplen = g < 0x7f
| 0 | ||||||||||||||||||||||||
| 67 | grouping++; | - | ||||||||||||||||||||||||
| 68 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 69 | - | |||||||||||||||||||||||||
| 70 | if (i < grouplen
| 0 | ||||||||||||||||||||||||
| 71 | grouplen = i; never executed: grouplen = i; | 0 | ||||||||||||||||||||||||
| 72 | - | |||||||||||||||||||||||||
| 73 | d -= grouplen; | - | ||||||||||||||||||||||||
| 74 | i -= grouplen; | - | ||||||||||||||||||||||||
| 75 | memcpy (d, buf + i, grouplen); | - | ||||||||||||||||||||||||
| 76 | if (i == 0
| 0 | ||||||||||||||||||||||||
| 77 | return never executed: d;return d;never executed: return d; | 0 | ||||||||||||||||||||||||
| 78 | - | |||||||||||||||||||||||||
| 79 | d -= thousands_seplen; | - | ||||||||||||||||||||||||
| 80 | memcpy (d, thousands_sep, thousands_seplen); | - | ||||||||||||||||||||||||
| 81 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 82 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 83 | char * | - | ||||||||||||||||||||||||
| 84 | human_readable (uintmax_t n, char *buf, int opts, | - | ||||||||||||||||||||||||
| 85 | uintmax_t from_block_size, uintmax_t to_block_size) | - | ||||||||||||||||||||||||
| 86 | { | - | ||||||||||||||||||||||||
| 87 | int inexact_style = | - | ||||||||||||||||||||||||
| 88 | opts & (human_round_to_nearest | human_floor | human_ceiling); | - | ||||||||||||||||||||||||
| 89 | unsigned int base = opts & human_base_1024
| 224-4623 | ||||||||||||||||||||||||
| 90 | uintmax_t amt; | - | ||||||||||||||||||||||||
| 91 | int tenths; | - | ||||||||||||||||||||||||
| 92 | int exponent = -1; | - | ||||||||||||||||||||||||
| 93 | int exponent_max = sizeof power_letter - 1; | - | ||||||||||||||||||||||||
| 94 | char *p; | - | ||||||||||||||||||||||||
| 95 | char *psuffix; | - | ||||||||||||||||||||||||
| 96 | char const *integerlim; | - | ||||||||||||||||||||||||
| 97 | - | |||||||||||||||||||||||||
| 98 | - | |||||||||||||||||||||||||
| 99 | - | |||||||||||||||||||||||||
| 100 | - | |||||||||||||||||||||||||
| 101 | - | |||||||||||||||||||||||||
| 102 | int rounding; | - | ||||||||||||||||||||||||
| 103 | - | |||||||||||||||||||||||||
| 104 | char const *decimal_point = "."; | - | ||||||||||||||||||||||||
| 105 | size_t decimal_pointlen = 1; | - | ||||||||||||||||||||||||
| 106 | char const *grouping = ""; | - | ||||||||||||||||||||||||
| 107 | char const *thousands_sep = ""; | - | ||||||||||||||||||||||||
| 108 | struct lconv const *l = localeconv (); | - | ||||||||||||||||||||||||
| 109 | size_t pointlen = strlen (l->decimal_point); | - | ||||||||||||||||||||||||
| 110 | if (0 < pointlen
| 0-4847 | ||||||||||||||||||||||||
| 111 | 16
| 0-4847 | ||||||||||||||||||||||||
| 112 | ) | - | ||||||||||||||||||||||||
| 113 | { | - | ||||||||||||||||||||||||
| 114 | decimal_point = l->decimal_point; | - | ||||||||||||||||||||||||
| 115 | decimal_pointlen = pointlen; | - | ||||||||||||||||||||||||
| 116 | } executed 4847 times by 6 tests: end of blockExecuted by:
| 4847 | ||||||||||||||||||||||||
| 117 | grouping = l->grouping; | - | ||||||||||||||||||||||||
| 118 | if (strlen (l->thousands_sep) <=
| 0-4847 | ||||||||||||||||||||||||
| 119 | 16
| 0-4847 | ||||||||||||||||||||||||
| 120 | ) | - | ||||||||||||||||||||||||
| 121 | thousands_sep = l->thousands_sep; executed 4847 times by 6 tests: thousands_sep = l->thousands_sep;Executed by:
| 4847 | ||||||||||||||||||||||||
| 122 | - | |||||||||||||||||||||||||
| 123 | - | |||||||||||||||||||||||||
| 124 | psuffix = buf + ((2 * sizeof (uintmax_t) * 8 * 146 / 485 + 1) * ( | - | ||||||||||||||||||||||||
| 125 | 16 | - | ||||||||||||||||||||||||
| 126 | + 1) - | - | ||||||||||||||||||||||||
| 127 | 16 | - | ||||||||||||||||||||||||
| 128 | + 1 + 3) - 1 - 3; | - | ||||||||||||||||||||||||
| 129 | p = psuffix; | - | ||||||||||||||||||||||||
| 130 | - | |||||||||||||||||||||||||
| 131 | - | |||||||||||||||||||||||||
| 132 | - | |||||||||||||||||||||||||
| 133 | - | |||||||||||||||||||||||||
| 134 | if (to_block_size <= from_block_size
| 1975-2872 | ||||||||||||||||||||||||
| 135 | { | - | ||||||||||||||||||||||||
| 136 | if (from_block_size % to_block_size == 0
| 147-1828 | ||||||||||||||||||||||||
| 137 | { | - | ||||||||||||||||||||||||
| 138 | uintmax_t multiplier = from_block_size / to_block_size; | - | ||||||||||||||||||||||||
| 139 | amt = n * multiplier; | - | ||||||||||||||||||||||||
| 140 | if (amt / multiplier == n
| 0-1828 | ||||||||||||||||||||||||
| 141 | { | - | ||||||||||||||||||||||||
| 142 | tenths = 0; | - | ||||||||||||||||||||||||
| 143 | rounding = 0; | - | ||||||||||||||||||||||||
| 144 | goto executed 1828 times by 5 tests: use_integer_arithmetic;goto use_integer_arithmetic;Executed by:
executed 1828 times by 5 tests: goto use_integer_arithmetic;Executed by:
| 1828 | ||||||||||||||||||||||||
| 145 | } | - | ||||||||||||||||||||||||
| 146 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 147 | } executed 147 times by 1 test: end of blockExecuted by:
| 147 | ||||||||||||||||||||||||
| 148 | else if (from_block_size != 0
| 0-2872 | ||||||||||||||||||||||||
| 149 | { | - | ||||||||||||||||||||||||
| 150 | uintmax_t divisor = to_block_size / from_block_size; | - | ||||||||||||||||||||||||
| 151 | uintmax_t r10 = (n % divisor) * 10; | - | ||||||||||||||||||||||||
| 152 | uintmax_t r2 = (r10 % divisor) * 2; | - | ||||||||||||||||||||||||
| 153 | amt = n / divisor; | - | ||||||||||||||||||||||||
| 154 | tenths = r10 / divisor; | - | ||||||||||||||||||||||||
| 155 | rounding = r2 < divisor
| 4-2865 | ||||||||||||||||||||||||
| 156 | goto executed 2869 times by 5 tests: use_integer_arithmetic;goto use_integer_arithmetic;Executed by:
executed 2869 times by 5 tests: goto use_integer_arithmetic;Executed by:
| 2869 | ||||||||||||||||||||||||
| 157 | } | - | ||||||||||||||||||||||||
| 158 | - | |||||||||||||||||||||||||
| 159 | { | - | ||||||||||||||||||||||||
| 160 | - | |||||||||||||||||||||||||
| 161 | - | |||||||||||||||||||||||||
| 162 | - | |||||||||||||||||||||||||
| 163 | - | |||||||||||||||||||||||||
| 164 | long double dto_block_size = to_block_size; | - | ||||||||||||||||||||||||
| 165 | long double damt = n * (from_block_size / dto_block_size); | - | ||||||||||||||||||||||||
| 166 | size_t buflen; | - | ||||||||||||||||||||||||
| 167 | size_t nonintegerlen; | - | ||||||||||||||||||||||||
| 168 | - | |||||||||||||||||||||||||
| 169 | if (! (opts & human_autoscale)
| 0-150 | ||||||||||||||||||||||||
| 170 | { | - | ||||||||||||||||||||||||
| 171 | sprintf (buf, "%.0Lf", adjust_value (inexact_style, damt)); | - | ||||||||||||||||||||||||
| 172 | buflen = strlen (buf); | - | ||||||||||||||||||||||||
| 173 | nonintegerlen = 0; | - | ||||||||||||||||||||||||
| 174 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 175 | else | - | ||||||||||||||||||||||||
| 176 | { | - | ||||||||||||||||||||||||
| 177 | long double e = 1; | - | ||||||||||||||||||||||||
| 178 | exponent = 0; | - | ||||||||||||||||||||||||
| 179 | - | |||||||||||||||||||||||||
| 180 | do | - | ||||||||||||||||||||||||
| 181 | { | - | ||||||||||||||||||||||||
| 182 | e *= base; | - | ||||||||||||||||||||||||
| 183 | exponent++; | - | ||||||||||||||||||||||||
| 184 | } executed 237 times by 1 test: end of blockExecuted by:
| 237 | ||||||||||||||||||||||||
| 185 | while (e * base <= damt
| 0-150 | ||||||||||||||||||||||||
| 186 | - | |||||||||||||||||||||||||
| 187 | damt /= e; | - | ||||||||||||||||||||||||
| 188 | - | |||||||||||||||||||||||||
| 189 | sprintf (buf, "%.1Lf", adjust_value (inexact_style, damt)); | - | ||||||||||||||||||||||||
| 190 | buflen = strlen (buf); | - | ||||||||||||||||||||||||
| 191 | nonintegerlen = decimal_pointlen + 1; | - | ||||||||||||||||||||||||
| 192 | - | |||||||||||||||||||||||||
| 193 | if (1 + nonintegerlen + ! (opts & human_base_1024) < buflen
| 70-80 | ||||||||||||||||||||||||
| 194 | || ((
| 0-80 | ||||||||||||||||||||||||
| 195 | && buf[buflen - 1] == '0'
| 0 | ||||||||||||||||||||||||
| 196 | { | - | ||||||||||||||||||||||||
| 197 | sprintf (buf, "%.0Lf", | - | ||||||||||||||||||||||||
| 198 | adjust_value (inexact_style, damt * 10) / 10); | - | ||||||||||||||||||||||||
| 199 | buflen = strlen (buf); | - | ||||||||||||||||||||||||
| 200 | nonintegerlen = 0; | - | ||||||||||||||||||||||||
| 201 | } executed 70 times by 1 test: end of blockExecuted by:
| 70 | ||||||||||||||||||||||||
| 202 | } executed 150 times by 1 test: end of blockExecuted by:
| 150 | ||||||||||||||||||||||||
| 203 | - | |||||||||||||||||||||||||
| 204 | p = psuffix - buflen; | - | ||||||||||||||||||||||||
| 205 | memmove (p, buf, buflen); | - | ||||||||||||||||||||||||
| 206 | integerlim = p + buflen - nonintegerlen; | - | ||||||||||||||||||||||||
| 207 | } | - | ||||||||||||||||||||||||
| 208 | goto executed 150 times by 1 test: do_grouping;goto do_grouping;Executed by:
executed 150 times by 1 test: goto do_grouping;Executed by:
| 150 | ||||||||||||||||||||||||
| 209 | - | |||||||||||||||||||||||||
| 210 | use_integer_arithmetic: | - | ||||||||||||||||||||||||
| 211 | { | - | ||||||||||||||||||||||||
| 212 | - | |||||||||||||||||||||||||
| 213 | - | |||||||||||||||||||||||||
| 214 | - | |||||||||||||||||||||||||
| 215 | - | |||||||||||||||||||||||||
| 216 | - | |||||||||||||||||||||||||
| 217 | if (opts & human_autoscale
| 375-4322 | ||||||||||||||||||||||||
| 218 | { | - | ||||||||||||||||||||||||
| 219 | exponent = 0; | - | ||||||||||||||||||||||||
| 220 | - | |||||||||||||||||||||||||
| 221 | if (base <= amt
| 134-241 | ||||||||||||||||||||||||
| 222 | { | - | ||||||||||||||||||||||||
| 223 | do | - | ||||||||||||||||||||||||
| 224 | { | - | ||||||||||||||||||||||||
| 225 | unsigned int r10 = (amt % base) * 10 + tenths; | - | ||||||||||||||||||||||||
| 226 | unsigned int r2 = (r10 % base) * 2 + (rounding >> 1); | - | ||||||||||||||||||||||||
| 227 | amt /= base; | - | ||||||||||||||||||||||||
| 228 | tenths = r10 / base; | - | ||||||||||||||||||||||||
| 229 | rounding = (r2 < base
| 68-316 | ||||||||||||||||||||||||
| 230 | ? (r2 + rounding) != 0 | - | ||||||||||||||||||||||||
| 231 | : 2 + (base < r2 + rounding)); | - | ||||||||||||||||||||||||
| 232 | exponent++; | - | ||||||||||||||||||||||||
| 233 | } executed 384 times by 3 tests: end of blockExecuted by:
| 384 | ||||||||||||||||||||||||
| 234 | while (base <= amt
| 0-241 | ||||||||||||||||||||||||
| 235 | - | |||||||||||||||||||||||||
| 236 | if (amt < 10
| 108-133 | ||||||||||||||||||||||||
| 237 | { | - | ||||||||||||||||||||||||
| 238 | if (inexact_style == human_round_to_nearest
| 14-94 | ||||||||||||||||||||||||
| 239 | ? 2 < rounding + (tenths & 1)
| 14-94 | ||||||||||||||||||||||||
| 240 | : inexact_style == human_ceiling
| 0-94 | ||||||||||||||||||||||||
| 241 | { | - | ||||||||||||||||||||||||
| 242 | tenths++; | - | ||||||||||||||||||||||||
| 243 | rounding = 0; | - | ||||||||||||||||||||||||
| 244 | - | |||||||||||||||||||||||||
| 245 | if (tenths == 10
| 1-13 | ||||||||||||||||||||||||
| 246 | { | - | ||||||||||||||||||||||||
| 247 | amt++; | - | ||||||||||||||||||||||||
| 248 | tenths = 0; | - | ||||||||||||||||||||||||
| 249 | } executed 1 time by 1 test: end of blockExecuted by:
| 1 | ||||||||||||||||||||||||
| 250 | } executed 14 times by 3 tests: end of blockExecuted by:
| 14 | ||||||||||||||||||||||||
| 251 | - | |||||||||||||||||||||||||
| 252 | if (amt < 10
| 0-108 | ||||||||||||||||||||||||
| 253 | && (tenths
| 27-81 | ||||||||||||||||||||||||
| 254 | { | - | ||||||||||||||||||||||||
| 255 | *--p = '0' + tenths; | - | ||||||||||||||||||||||||
| 256 | p -= decimal_pointlen; | - | ||||||||||||||||||||||||
| 257 | memcpy (p, decimal_point, decimal_pointlen); | - | ||||||||||||||||||||||||
| 258 | tenths = rounding = 0; | - | ||||||||||||||||||||||||
| 259 | } executed 56 times by 3 tests: end of blockExecuted by:
| 56 | ||||||||||||||||||||||||
| 260 | } executed 108 times by 3 tests: end of blockExecuted by:
| 108 | ||||||||||||||||||||||||
| 261 | } executed 241 times by 3 tests: end of blockExecuted by:
| 241 | ||||||||||||||||||||||||
| 262 | } executed 375 times by 3 tests: end of blockExecuted by:
| 375 | ||||||||||||||||||||||||
| 263 | - | |||||||||||||||||||||||||
| 264 | if (inexact_style == human_round_to_nearest
| 47-4650 | ||||||||||||||||||||||||
| 265 | ? 5 < tenths + (0 < rounding + (amt & 1))
| 47-4650 | ||||||||||||||||||||||||
| 266 | : inexact_style == human_ceiling
| 0-4650 | ||||||||||||||||||||||||
| 267 | { | - | ||||||||||||||||||||||||
| 268 | amt++; | - | ||||||||||||||||||||||||
| 269 | - | |||||||||||||||||||||||||
| 270 | if ((
| 16-31 | ||||||||||||||||||||||||
| 271 | && amt == base
| 0-31 | ||||||||||||||||||||||||
| 272 | { | - | ||||||||||||||||||||||||
| 273 | exponent++; | - | ||||||||||||||||||||||||
| 274 | if (! (opts & human_suppress_point_zero)
| 0 | ||||||||||||||||||||||||
| 275 | { | - | ||||||||||||||||||||||||
| 276 | *--p = '0'; | - | ||||||||||||||||||||||||
| 277 | p -= decimal_pointlen; | - | ||||||||||||||||||||||||
| 278 | memcpy (p, decimal_point, decimal_pointlen); | - | ||||||||||||||||||||||||
| 279 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 280 | amt = 1; | - | ||||||||||||||||||||||||
| 281 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 282 | } executed 47 times by 3 tests: end of blockExecuted by:
| 47 | ||||||||||||||||||||||||
| 283 | - | |||||||||||||||||||||||||
| 284 | integerlim = p; | - | ||||||||||||||||||||||||
| 285 | - | |||||||||||||||||||||||||
| 286 | do | - | ||||||||||||||||||||||||
| 287 | { | - | ||||||||||||||||||||||||
| 288 | int digit = amt % 10; | - | ||||||||||||||||||||||||
| 289 | *--p = digit + '0'; | - | ||||||||||||||||||||||||
| 290 | } executed 10791 times by 6 tests: end of blockExecuted by:
| 10791 | ||||||||||||||||||||||||
| 291 | while ((
| 4697-6094 | ||||||||||||||||||||||||
| 292 | } | - | ||||||||||||||||||||||||
| 293 | - | |||||||||||||||||||||||||
| 294 | do_grouping: code before this statement executed 4697 times by 6 tests: do_grouping:Executed by:
| 4697 | ||||||||||||||||||||||||
| 295 | if (opts & human_group_digits
| 0-4847 | ||||||||||||||||||||||||
| 296 | p = group_number (p, integerlim - p, grouping, thousands_sep); never executed: p = group_number (p, integerlim - p, grouping, thousands_sep); | 0 | ||||||||||||||||||||||||
| 297 | - | |||||||||||||||||||||||||
| 298 | if (opts & human_SI
| 525-4322 | ||||||||||||||||||||||||
| 299 | { | - | ||||||||||||||||||||||||
| 300 | if (exponent < 0
| 0-525 | ||||||||||||||||||||||||
| 301 | { | - | ||||||||||||||||||||||||
| 302 | uintmax_t power; | - | ||||||||||||||||||||||||
| 303 | exponent = 0; | - | ||||||||||||||||||||||||
| 304 | for (power = 1; power < to_block_size
| 0 | ||||||||||||||||||||||||
| 305 | if (++
| 0 | ||||||||||||||||||||||||
| 306 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 307 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 308 | - | |||||||||||||||||||||||||
| 309 | if ((
| 0-525 | ||||||||||||||||||||||||
| 310 | * executed 454 times by 1 test: psuffix++ = ' ';*psuffix++ = ' ';Executed by:
executed 454 times by 1 test: *psuffix++ = ' ';Executed by:
| 454 | ||||||||||||||||||||||||
| 311 | - | |||||||||||||||||||||||||
| 312 | if (exponent
| 134-391 | ||||||||||||||||||||||||
| 313 | * executed 391 times by 3 tests: psuffix++ = (! (opts & human_base_1024)*psuffix++ = (! (opts & human_base_1024) && exponent == 1 ? 'k' : power_letter[exponent]);Executed by:
executed 391 times by 3 tests: *psuffix++ = (! (opts & human_base_1024) && exponent == 1 ? 'k' : power_letter[exponent]);Executed by:
| 86-391 | ||||||||||||||||||||||||
| 314 | ? 'k' executed 391 times by 3 tests: *psuffix++ = (! (opts & human_base_1024) && exponent == 1 ? 'k' : power_letter[exponent]);Executed by:
| 391 | ||||||||||||||||||||||||
| 315 | : power_letter[exponent]); executed 391 times by 3 tests: *psuffix++ = (! (opts & human_base_1024) && exponent == 1 ? 'k' : power_letter[exponent]);Executed by:
| 391 | ||||||||||||||||||||||||
| 316 | - | |||||||||||||||||||||||||
| 317 | if (opts & human_B
| 71-454 | ||||||||||||||||||||||||
| 318 | { | - | ||||||||||||||||||||||||
| 319 | if ((
| 67-300 | ||||||||||||||||||||||||
| 320 | * executed 87 times by 1 test: psuffix++ = 'i';*psuffix++ = 'i';Executed by:
executed 87 times by 1 test: *psuffix++ = 'i';Executed by:
| 87 | ||||||||||||||||||||||||
| 321 | *psuffix++ = 'B'; | - | ||||||||||||||||||||||||
| 322 | } executed 454 times by 1 test: end of blockExecuted by:
| 454 | ||||||||||||||||||||||||
| 323 | } executed 525 times by 3 tests: end of blockExecuted by:
| 525 | ||||||||||||||||||||||||
| 324 | - | |||||||||||||||||||||||||
| 325 | *psuffix = '\0'; | - | ||||||||||||||||||||||||
| 326 | - | |||||||||||||||||||||||||
| 327 | return executed 4847 times by 6 tests: p;return p;Executed by:
executed 4847 times by 6 tests: return p;Executed by:
| 4847 | ||||||||||||||||||||||||
| 328 | } | - | ||||||||||||||||||||||||
| 329 | static char const *const block_size_args[] = { "human-readable", "si", 0 }; | - | ||||||||||||||||||||||||
| 330 | static int const block_size_opts[] = | - | ||||||||||||||||||||||||
| 331 | { | - | ||||||||||||||||||||||||
| 332 | human_autoscale + human_SI + human_base_1024, | - | ||||||||||||||||||||||||
| 333 | human_autoscale + human_SI | - | ||||||||||||||||||||||||
| 334 | }; | - | ||||||||||||||||||||||||
| 335 | - | |||||||||||||||||||||||||
| 336 | static uintmax_t | - | ||||||||||||||||||||||||
| 337 | default_block_size (void) | - | ||||||||||||||||||||||||
| 338 | { | - | ||||||||||||||||||||||||
| 339 | return executed 1622 times by 5 tests: getenv ("POSIXLY_CORRECT") ? 512 : 1024;return getenv ("POSIXLY_CORRECT") ? 512 : 1024;Executed by:
executed 1622 times by 5 tests: return getenv ("POSIXLY_CORRECT") ? 512 : 1024;Executed by:
| 1622 | ||||||||||||||||||||||||
| 340 | } | - | ||||||||||||||||||||||||
| 341 | - | |||||||||||||||||||||||||
| 342 | static strtol_error | - | ||||||||||||||||||||||||
| 343 | humblock (char const *spec, uintmax_t *block_size, int *options) | - | ||||||||||||||||||||||||
| 344 | { | - | ||||||||||||||||||||||||
| 345 | int i; | - | ||||||||||||||||||||||||
| 346 | int opts = 0; | - | ||||||||||||||||||||||||
| 347 | - | |||||||||||||||||||||||||
| 348 | if (! spec
| 183-1618 | ||||||||||||||||||||||||
| 349 | && ! (spec = getenv ("BLOCK_SIZE"))
| 0-1618 | ||||||||||||||||||||||||
| 350 | && ! (spec = getenv ("BLOCKSIZE"))
| 0-1618 | ||||||||||||||||||||||||
| 351 | * executed 1618 times by 5 tests: block_size = default_block_size ();*block_size = default_block_size ();Executed by:
executed 1618 times by 5 tests: *block_size = default_block_size ();Executed by:
| 1618 | ||||||||||||||||||||||||
| 352 | else | - | ||||||||||||||||||||||||
| 353 | { | - | ||||||||||||||||||||||||
| 354 | if (*
| 0-183 | ||||||||||||||||||||||||
| 355 | { | - | ||||||||||||||||||||||||
| 356 | opts |= human_group_digits; | - | ||||||||||||||||||||||||
| 357 | spec++; | - | ||||||||||||||||||||||||
| 358 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 359 | - | |||||||||||||||||||||||||
| 360 | if (0 <= (i = argmatch (spec, block_size_args, (char const *) (block_size_opts), sizeof *(block_size_opts)))
| 0-183 | ||||||||||||||||||||||||
| 361 | { | - | ||||||||||||||||||||||||
| 362 | opts |= block_size_opts[i]; | - | ||||||||||||||||||||||||
| 363 | *block_size = 1; | - | ||||||||||||||||||||||||
| 364 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 365 | else | - | ||||||||||||||||||||||||
| 366 | { | - | ||||||||||||||||||||||||
| 367 | char *ptr; | - | ||||||||||||||||||||||||
| 368 | strtol_error e = xstrtoumax (spec, &ptr, 0, block_size, | - | ||||||||||||||||||||||||
| 369 | "eEgGkKmMpPtTyYzZ0"); | - | ||||||||||||||||||||||||
| 370 | if (e != LONGINT_OK
| 6-177 | ||||||||||||||||||||||||
| 371 | { | - | ||||||||||||||||||||||||
| 372 | *options = 0; | - | ||||||||||||||||||||||||
| 373 | return executed 6 times by 4 tests: e;return e;Executed by:
executed 6 times by 4 tests: return e;Executed by:
| 6 | ||||||||||||||||||||||||
| 374 | } | - | ||||||||||||||||||||||||
| 375 | for (; ! ('0' <= *spec
| 0-177 | ||||||||||||||||||||||||
| 376 | if (spec == ptr
| 0 | ||||||||||||||||||||||||
| 377 | { | - | ||||||||||||||||||||||||
| 378 | opts |= human_SI; | - | ||||||||||||||||||||||||
| 379 | if (ptr[-1] == 'B'
| 0 | ||||||||||||||||||||||||
| 380 | opts |= human_B; never executed: opts |= human_B; | 0 | ||||||||||||||||||||||||
| 381 | if (ptr[-1] != 'B'
| 0 | ||||||||||||||||||||||||
| 382 | opts |= human_base_1024; never executed: opts |= human_base_1024; | 0 | ||||||||||||||||||||||||
| 383 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 384 | } | - | ||||||||||||||||||||||||
| 385 | } executed 177 times by 2 tests: end of blockExecuted by:
| 177 | ||||||||||||||||||||||||
| 386 | } | - | ||||||||||||||||||||||||
| 387 | - | |||||||||||||||||||||||||
| 388 | *options = opts; | - | ||||||||||||||||||||||||
| 389 | return executed 1795 times by 5 tests: LONGINT_OK;return LONGINT_OK;Executed by:
executed 1795 times by 5 tests: return LONGINT_OK;Executed by:
| 1795 | ||||||||||||||||||||||||
| 390 | } | - | ||||||||||||||||||||||||
| 391 | - | |||||||||||||||||||||||||
| 392 | enum strtol_error | - | ||||||||||||||||||||||||
| 393 | human_options (char const *spec, int *opts, uintmax_t *block_size) | - | ||||||||||||||||||||||||
| 394 | { | - | ||||||||||||||||||||||||
| 395 | strtol_error e = humblock (spec, block_size, opts); | - | ||||||||||||||||||||||||
| 396 | if (*
| 4-1797 | ||||||||||||||||||||||||
| 397 | { | - | ||||||||||||||||||||||||
| 398 | *block_size = default_block_size (); | - | ||||||||||||||||||||||||
| 399 | e = LONGINT_INVALID; | - | ||||||||||||||||||||||||
| 400 | } executed 4 times by 3 tests: end of blockExecuted by:
| 4 | ||||||||||||||||||||||||
| 401 | return executed 1801 times by 5 tests: e;return e;Executed by:
executed 1801 times by 5 tests: return e;Executed by:
| 1801 | ||||||||||||||||||||||||
| 402 | } | - | ||||||||||||||||||||||||
| Switch to Source code | Preprocessed file |