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

Function rewriteConfigFormatMemory

app/redis-6.2.6/src/config.c:1265–1279  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

1263/* Write the long long 'bytes' value as a string in a way that is parsable
1264 * inside redis.conf. If possible uses the GB, MB, KB notation. */
1265int rewriteConfigFormatMemory(char *buf, size_t len, long long bytes) {
1266 int gb = 1024*1024*1024;
1267 int mb = 1024*1024;
1268 int kb = 1024;
1269
1270 if (bytes && (bytes % gb) == 0) {
1271 return snprintf(buf,len,"%lldgb",bytes/gb);
1272 } else if (bytes && (bytes % mb) == 0) {
1273 return snprintf(buf,len,"%lldmb",bytes/mb);
1274 } else if (bytes && (bytes % kb) == 0) {
1275 return snprintf(buf,len,"%lldkb",bytes/kb);
1276 } else {
1277 return snprintf(buf,len,"%lld",bytes);
1278 }
1279}
1280
1281/* Rewrite a simple "option-name <bytes>" configuration option. */
1282void rewriteConfigBytesOption(struct rewriteConfigState *state, const char *option, long long value, long long defvalue) {

Calls 1

snprintfFunction · 0.85

Tested by

no test coverage detected