fmt_human(3)

πŸ“¦
version 0.34 Β· 2 versions
  • 0.34 Β· alpine 3.24, debian bookworm, debian trixie, nixos 26.05, nixpkgs unstable, opensuse-leap 16.0, ubuntu noble, ubuntu questing, ubuntu resolute, ubuntu stonking (latest)
  • 0.30 Β· fedora 43, fedora 44, ubuntu jammy
, in alpine 3.24, debian bookworm, debian trixie, nixos 26.05, nixpkgs unstable, opensuse-leap 16.0, ubuntu noble, ubuntu questing, ubuntu resolute, ubuntu stonking

πŸ’– fmt_human(3) πŸ’–

okay bestie, welcome to the Library Functions Manual, section 3, where we talk about fmt_human β€” she's a little function with big main character energy, and yes, she lives in the library functions girlies. let's get into it 🫢


✨ NAME ✨

fmt_human β€” writes a human readable ASCII representation of a long integer. literally her whole job. iconic of her tbh πŸ’…


🌸 SYNTAX 🌸

#include <libowfat/fmt.h>

size_t fmt_human(char *dest,unsigned long long source);

copy it exactly, no notes, she's perfect as is 😌


πŸ¦‹ DESCRIPTION πŸ¦‹

so basically, fmt_human takes your source (a long integer, but make it cute) and writes a human readable ASCII representation of it into dest. then she tells you how many bytes she wrote, by returning that number. no cap.

the result is giving major "file size output of ls -H" vibes. like:

  • 1000 becomes "1.0k" ✨
  • 1000000 becomes "1.0M" ✨
  • and so on and so on for "G" and "T" πŸŽ€

one thing to know, and this is important, bestie: fmt_human does not append \0. she's not gonna null-terminate that string for you. she said figure it out πŸ’€

now, if dest equals FMT_LEN (i.e. it is zero), then fmt_human won't write anything β€” instead she just returns the number of bytes she would have written. so you can ask her "hey how big would this be" and she'll tell you, no actual writing required. queen behaviour fr fr πŸ‘‘

also, heads up: the output of fmt_human can not exceed 11 bytes (that's assuming unsigned long long has 64 bits). so don't come for her with a buffer smaller than that, mwah πŸ’‹


πŸ”₯ SEE ALSO πŸ”₯

go read those too, they're her besties, the friend group is immaculate 🌈


sign-off time, babe πŸ’œ this little love letter came from the Library Functions Manual and it's all about fmt_human(3). that's the whole page, you ate it up, mwah πŸŽ€βœ¨