MCPcopy Create free account
hub / github.com/esnet/iperf / unit_snprintf

Function unit_snprintf

src/units.c:291–373  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

289 * ------------------------------------------------------------------- */
290
291 void unit_snprintf(char *s, int inLen,
292 double inNum, char inFormat)
293 {
294 int conv;
295 const char *suffix;
296 const char *format;
297
298 /* convert to bits for [bkmga] */
299 if (!isupper((int) inFormat))
300 {
301 inNum *= 8;
302 }
303 switch (toupper((u_char)inFormat))
304 {
305 case 'B':
306 conv = UNIT_CONV;
307 break;
308 case 'K':
309 conv = KILO_CONV;
310 break;
311 case 'M':
312 conv = MEGA_CONV;
313 break;
314 case 'G':
315 conv = GIGA_CONV;
316 break;
317 case 'T':
318 conv = TERA_CONV;
319 break;
320
321 default:
322 case 'A':
323 {
324 double tmpNum = inNum;
325 conv = UNIT_CONV;
326
327 if (isupper((int) inFormat))
328 {
329 while (tmpNum >= 1024.0 && conv < TERA_CONV)
330 {
331 tmpNum /= 1024.0;
332 conv++;
333 }
334 } else
335 {
336 while (tmpNum >= 1000.0 && conv < TERA_CONV)
337 {
338 tmpNum /= 1000.0;
339 conv++;
340 }
341 }
342 break;
343 }
344 }
345
346 if (!isupper((int) inFormat))
347 {
348 inNum *= conversion_bits[conv];

Callers 4

iperf_print_intermediateFunction · 0.85
iperf_print_resultsFunction · 0.85
print_interval_resultsFunction · 0.85
mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…