From cfb344892209783a600e80053dba1cfeee4bd16a Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Wed, 25 May 2022 15:38:48 +0200 Subject: cutils: add functions for IEC and SI prefixes Extract the knowledge of IEC and SI prefixes out of size_to_str and freq_to_str, so that it can be reused when printing statistics. Signed-off-by: Paolo Bonzini --- include/qemu/cutils.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'include/qemu') diff --git a/include/qemu/cutils.h b/include/qemu/cutils.h index 40e10e1..d3e532b 100644 --- a/include/qemu/cutils.h +++ b/include/qemu/cutils.h @@ -1,6 +1,24 @@ #ifndef QEMU_CUTILS_H #define QEMU_CUTILS_H +/* + * si_prefix: + * @exp10: exponent of 10, a multiple of 3 between -18 and 18 inclusive. + * + * Return a SI prefix (n, u, m, K, M, etc.) corresponding + * to the given exponent of 10. + */ +const char *si_prefix(unsigned int exp10); + +/* + * iec_binary_prefix: + * @exp2: exponent of 2, a multiple of 10 between 0 and 60 inclusive. + * + * Return an IEC binary prefix (Ki, Mi, etc.) corresponding + * to the given exponent of 2. + */ +const char *iec_binary_prefix(unsigned int exp2); + /** * pstrcpy: * @buf: buffer to copy string into -- cgit v1.1