Manual browser: humanize_number(9)
|HUMANIZE_NUMBER(9)||Kernel Developer's Manual||HUMANIZE_NUMBER(9)|
NAMEhumanize_number, format_bytes — human readable numbers
humanize_number(char *buf, size_t len, uint64_t number, const char *suffix, int divisor);
format_bytes(char *buf, size_t len, uint64_t number);
DESCRIPTIONThe humanize_number() function formats the unsigned 64-bit quantity given in number into buf. A space and then suffix is appended to the end. The supplied buf must be at least len bytes long.
If the formatted number (including suffix) is too long to fit into buf, humanize_number() divides number by divisor until it will fit. In this case, suffix is prefixed with the appropriate SI designator. Suitable values of divisor are 1024 or 1000 to remain consistent with the common meanings of the SI designator prefixes.
The prefixes are:
The len argument must be at least 4 plus the length of suffix, in order to ensure a useful result in buf.
The format_bytes() function is a front-end to humanize_number(). It calls the latter with a suffix of “B”. Also, if the suffix in the returned buf would not have a prefix, the suffix is removed. This means that a result of “100000” occurs, instead of “100000 B”.
RETURN VALUESBoth functions return the number of characters stored in buf (excluding the terminating NUL) upon success, or -1 upon failure.
HISTORYThese functions first appeared in NetBSD 1.5.
|August 7, 2010||NetBSD 7.0|