summaryrefslogtreecommitdiffstats
path: root/src/vppinfra
diff options
context:
space:
mode:
Diffstat (limited to 'src/vppinfra')
-rw-r--r--src/vppinfra/format.h3
-rw-r--r--src/vppinfra/std-formats.c18
2 files changed, 21 insertions, 0 deletions
diff --git a/src/vppinfra/format.h b/src/vppinfra/format.h
index cad9b0e0ef2..b70384c0e41 100644
--- a/src/vppinfra/format.h
+++ b/src/vppinfra/format.h
@@ -287,6 +287,9 @@ unformat_function_t unformat_eof;
/* Parse memory size e.g. 100, 100k, 100m, 100g. */
unformat_function_t unformat_memory_size;
+/* Format base 10 e.g. 100, 100K, 100M, 100G */
+u8 *format_base10 (u8 *s, va_list *va);
+
/* Unparse memory size e.g. 100, 100k, 100m, 100g. */
u8 *format_memory_size (u8 * s, va_list * va);
diff --git a/src/vppinfra/std-formats.c b/src/vppinfra/std-formats.c
index 1616001f9c5..1a150ead7bd 100644
--- a/src/vppinfra/std-formats.c
+++ b/src/vppinfra/std-formats.c
@@ -204,6 +204,24 @@ format_time_interval (u8 * s, va_list * args)
return s;
}
+/* Format base 10 e.g. 100, 100K, 100M, 100G */
+__clib_export u8 *
+format_base10 (u8 *s, va_list *va)
+{
+ uword size = va_arg (*va, uword);
+
+ if (size < 1000)
+ s = format (s, "%d", size);
+ else if (size < 1000000)
+ s = format (s, "%.2fK", (f64) size / 1000.);
+ else if (size < 1000000000)
+ s = format (s, "%.2fM", (f64) size / 1000000.);
+ else
+ s = format (s, "%.2fG", (f64) size / 1000000000.);
+
+ return s;
+}
+
/* Unparse memory size e.g. 100, 100k, 100m, 100g. */
__clib_export u8 *
format_memory_size (u8 * s, va_list * va)