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

Function rewriteConfigFormatMemory

src/config.cpp:1516–1530  ·  view source on GitHub ↗

Write the long long 'bytes' value as a string in a way that is parsable * inside keydb.conf. If possible uses the GB, MB, KB notation. */

Source from the content-addressed store, hash-verified

1514/* Write the long long 'bytes' value as a string in a way that is parsable
1515 * inside keydb.conf. If possible uses the GB, MB, KB notation. */
1516int rewriteConfigFormatMemory(char *buf, size_t len, long long bytes) {
1517 int gb = 1024*1024*1024;
1518 int mb = 1024*1024;
1519 int kb = 1024;
1520
1521 if (bytes && (bytes % gb) == 0) {
1522 return snprintf(buf,len,"%lldgb",bytes/gb);
1523 } else if (bytes && (bytes % mb) == 0) {
1524 return snprintf(buf,len,"%lldmb",bytes/mb);
1525 } else if (bytes && (bytes % kb) == 0) {
1526 return snprintf(buf,len,"%lldkb",bytes/kb);
1527 } else {
1528 return snprintf(buf,len,"%lld",bytes);
1529 }
1530}
1531
1532/* Rewrite a simple "option-name <bytes>" configuration option. */
1533void rewriteConfigBytesOption(struct rewriteConfigState *state, const char *option, long long value, long long defvalue) {

Calls

no outgoing calls

Tested by

no test coverage detected