Convert an amount of bytes into a human readable string in the form * of 100B, 2G, 100M, 4K, and so forth. */
| 5547 | /* Convert an amount of bytes into a human readable string in the form |
| 5548 | * of 100B, 2G, 100M, 4K, and so forth. */ |
| 5549 | void bytesToHuman(char *s, unsigned long long n, size_t bufsize) { |
| 5550 | double d; |
| 5551 | |
| 5552 | if (n < 1024) { |
| 5553 | /* Bytes */ |
| 5554 | snprintf(s,bufsize,"%lluB",n); |
| 5555 | } else if (n < (1024*1024)) { |
| 5556 | d = (double)n/(1024); |
| 5557 | snprintf(s,bufsize,"%.2fK",d); |
| 5558 | } else if (n < (1024LL*1024*1024)) { |
| 5559 | d = (double)n/(1024*1024); |
| 5560 | snprintf(s,bufsize,"%.2fM",d); |
| 5561 | } else if (n < (1024LL*1024*1024*1024)) { |
| 5562 | d = (double)n/(1024LL*1024*1024); |
| 5563 | snprintf(s,bufsize,"%.2fG",d); |
| 5564 | } else if (n < (1024LL*1024*1024*1024*1024)) { |
| 5565 | d = (double)n/(1024LL*1024*1024*1024); |
| 5566 | snprintf(s,bufsize,"%.2fT",d); |
| 5567 | } else if (n < (1024LL*1024*1024*1024*1024*1024)) { |
| 5568 | d = (double)n/(1024LL*1024*1024*1024*1024); |
| 5569 | snprintf(s,bufsize,"%.2fP",d); |
| 5570 | } else { |
| 5571 | /* Let's hope we never need this */ |
| 5572 | snprintf(s,bufsize,"%lluB",n); |
| 5573 | } |
| 5574 | } |
| 5575 | |
| 5576 | /* Characters we sanitize on INFO output to maintain expected format. */ |
| 5577 | static char unsafe_info_chars[] = "#:\n\r"; |
no outgoing calls
no test coverage detected