MCPcopy Create free account
hub / github.com/F-Stack/f-stack / bytesToHuman

Function bytesToHuman

app/redis-6.2.6/src/redis-cli.c:7956–7978  ·  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

7954/* Convert number of bytes into a human readable string of the form:
7955 * 100B, 2G, 100M, 4K, and so forth. */
7956void bytesToHuman(char *s, long long n) {
7957 double d;
7958
7959 if (n < 0) {
7960 *s = '-';
7961 s++;
7962 n = -n;
7963 }
7964 if (n < 1024) {
7965 /* Bytes */
7966 sprintf(s,"%lldB",n);
7967 return;
7968 } else if (n < (1024*1024)) {
7969 d = (double)n/(1024);
7970 sprintf(s,"%.2fK",d);
7971 } else if (n < (1024LL*1024*1024)) {
7972 d = (double)n/(1024*1024);
7973 sprintf(s,"%.2fM",d);
7974 } else if (n < (1024LL*1024*1024*1024)) {
7975 d = (double)n/(1024LL*1024*1024);
7976 sprintf(s,"%.2fG",d);
7977 }
7978}
7979
7980static void statMode(void) {
7981 redisReply *reply;

Callers 1

statModeFunction · 0.70

Calls 1

sprintfFunction · 0.85

Tested by

no test coverage detected