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. */
| 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. */ |
| 1265 | int 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. */ |
| 1282 | void rewriteConfigBytesOption(struct rewriteConfigState *state, const char *option, long long value, long long defvalue) { |
no test coverage detected