HUMANIZE_NUMBER(9)
π NAME π
okay bestie, welcome to HUMANIZE_NUMBER(9), straight out of the Kernel Developerβs Manual β this one is all about humanize_number and format_bytes, aka human readable numbers β¨. yes, the glow-up for numbers so they donβt look like a cursed wall of digits π
.
β¨ SYNOPSIS β¨
int
humanize_number(char *buf, size_t len, uint64_t number,
const char *suffix, int divisor);
int
format_bytes(char *buf, size_t len, uint64_t number);
π¦ DESCRIPTION π¦
so humanize_number() takes the unsigned 64-bit quantity in number and formats it into buf π«Ά. then it appends a space and then suffix to the end. the supplied buf must be at least len bytes long β no cap, that part matters π.
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:
kβ kilo, multiplier1024Mβ mega, multiplier1048576Gβ giga, multiplier1073741824Tβ tera, multiplier1099511627776Pβ peta, multiplier1125899906842624Eβ exa, multiplier1152921504606846976
bestie, do not skip this one π: thelenargument must be at least4plus the length ofsuffix, in order to ensure a useful result inbuf. itβs giving βhard requirement,β because it is π.
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 VALUES πΈ
both functions return the number of characters stored in buf (excluding the terminating NUL) upon success, or -1 upon failure π. slay when it works, -1 when it doesnβt π
.
π SEE ALSO π
β HISTORY β
these functions first appeared in NetBSD 1.5 π.
mwah π thatβs the whole page β brought to you by Debian, dated August 7, 2010, and signed HUMANIZE_NUMBER(9). periodt. π
π¦ where this page comes from
- nixpkgs unstable: netbsd-source 11.0
- Copyright (c) 1999 The NetBSD Foundation, Inc
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms