MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / bytesToHuman

Function bytesToHuman

src/redis-cli.c:6842–6864  ·  view source on GitHub ↗

Convert number of bytes into a human readable string of the form: * 100B, 2G, 100M, 4K, and so forth. */

Source from the content-addressed store, hash-verified

6840/* Convert number of bytes into a human readable string of the form:
6841 * 100B, 2G, 100M, 4K, and so forth. */
6842void bytesToHuman(char *s, long long n, size_t bufsize) {
6843 double d;
6844
6845 if (n < 0) {
6846 *s = '-';
6847 s++;
6848 n = -n;
6849 }
6850 if (n < 1024) {
6851 /* Bytes */
6852 snprintf(s,bufsize,"%lldB",n);
6853 return;
6854 } else if (n < (1024*1024)) {
6855 d = (double)n/(1024);
6856 snprintf(s,bufsize,"%.2fK",d);
6857 } else if (n < (1024LL*1024*1024)) {
6858 d = (double)n/(1024*1024);
6859 snprintf(s,bufsize,"%.2fM",d);
6860 } else if (n < (1024LL*1024*1024*1024)) {
6861 d = (double)n/(1024LL*1024*1024);
6862 snprintf(s,bufsize,"%.2fG",d);
6863 }
6864}
6865
6866static void statMode(void) {
6867 redisReply *reply;

Callers 1

statModeFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected