summaryrefslogtreecommitdiffstats
path: root/lib/utils.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/utils.c')
-rw-r--r--lib/utils.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/lib/utils.c b/lib/utils.c
index b507608..c7d3abd 100644
--- a/lib/utils.c
+++ b/lib/utils.c
@@ -151,6 +151,27 @@ double nl_cancel_down_bits(unsigned long long l, char **unit)
}
+int nl_rate2str(unsigned long long rate, int type, char *buf, size_t len)
+{
+ char *unit;
+ double frac;
+
+ switch (type) {
+ case NL_BYTE_RATE:
+ frac = nl_cancel_down_bytes(rate, &unit);
+ break;
+
+ case NL_BIT_RATE:
+ frac = nl_cancel_down_bits(rate, &unit);
+ break;
+
+ default:
+ BUG();
+ }
+
+ return snprintf(buf, len, "%.2f%s/s", frac, unit);
+}
+
/**
* Cancel down a micro second value
* @arg l micro seconds