Commit f9843118 authored by rswindell's avatar rswindell
Browse files

Add a precision argument to byte_estimate_to_str() so the caller can control

the number of decimal places in the resulting string.
parent 6ce7276c
......@@ -311,16 +311,16 @@ char* DLLCALL byte_count_to_str(int64_t bytes, char* str, size_t size)
This function also appends 'B' for exact byte counts (< 1024).
'unit' is the smallest divisor used.
*/
char* DLLCALL byte_estimate_to_str(int64_t bytes, char* str, size_t size, ulong unit)
char* DLLCALL byte_estimate_to_str(int64_t bytes, char* str, size_t size, ulong unit, int precision)
{
if(bytes >= one_tebibyte)
safe_snprintf(str, size, "%1.1fT", bytes/one_tebibyte);
safe_snprintf(str, size, "%1.*fT", precision, bytes/one_tebibyte);
else if(bytes >= one_gibibyte || unit == one_gibibyte)
safe_snprintf(str, size, "%1.1fG", bytes/one_gibibyte);
safe_snprintf(str, size, "%1.*fG", precision, bytes/one_gibibyte);
else if(bytes >= one_mebibyte || unit == one_mebibyte)
safe_snprintf(str, size, "%1.1fM", bytes/one_mebibyte);
safe_snprintf(str, size, "%1.*fM", precision, bytes/one_mebibyte);
else if(bytes >= one_kibibyte || unit == one_kibibyte)
safe_snprintf(str, size, "%1.1fK", bytes/one_kibibyte);
safe_snprintf(str, size, "%1.*fK", precision, bytes/one_kibibyte);
else
safe_snprintf(str, size, "%"PRIi64"B", bytes);
......
......@@ -374,7 +374,7 @@ DLLEXPORT double DLLCALL parse_duration(const char*);
DLLEXPORT char* DLLCALL duration_to_str(double value, char* str, size_t size);
DLLEXPORT char* DLLCALL duration_to_vstr(double value, char* str, size_t size);
DLLEXPORT char* DLLCALL byte_count_to_str(int64_t bytes, char* str, size_t size);
DLLEXPORT char* DLLCALL byte_estimate_to_str(int64_t bytes, char* str, size_t size, ulong unit);
DLLEXPORT char* DLLCALL byte_estimate_to_str(int64_t bytes, char* str, size_t size, ulong unit, int precision);
/* Microsoft (e.g. DOS/Win32) real-time system clock API (ticks since process started) */
typedef clock_t msclock_t;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment