fmt_uint0(3)
π fmt_uint0 β bestie's guide to zero-padded unsigned ints π
okay so you know the <libowfat/fmt.h> girlies? yeah, this is one of them. it's fmt_uint0 from the Library Functions Manual, and she is so iconic for one very specific job. let's get into it π«Ά
β¨ NAME β¨
fmt_uint0 β write a zero-padded ASCII representation of an unsigned integer
like. that's her whole thing. she takes an unsigned integer and writes it out as text, but with the cutest little 0 padding. no cap π
πΈ SYNTAX πΈ
#include <libowfat/fmt.h>
size_t fmt_uint0(char *dest,unsigned int source,
size_t n);
look at her. three params, one size_t return, zero drama. lowkey perfect.
π¦ DESCRIPTION π¦
so fmt_uint0 writes an ASCII representation ('0' to '9', base 10 β yes bestie, decimal, we're not doing anything weird here) of source to dest, and then it returns the number of bytes written. that's the whole vibe.
the moment that makes her special: the output gets padded with '0'-bytes until it encompasses at least n bytes. so if you ask for n and your number is short, she fills the front with zeros like she's decorating a cake π
β οΈ but listen β she will not be truncated if it does not fit. if your number is longer thann, she just writes the whole thing anyway.nis a minimum, not a limit. she does not shrink herself for anybody. periodt. π
and this one's important:
fmt_uint0 does not append \0. no null terminator, no lil safety net, nothing. if you want that you're gonna have to handle it yourself, bestie. iykyk π
π« the zero-dest trick π«
if dest equals FMT_LEN (i.e. is zero), fmt_uint0 returns the number of bytes it would have written.
that's the "not me, just measuring" mode. you get the length without actually writing anything to memory. extremely useful, highkey genius, obsessed with her fr fr β¨
π a lil convenience note π
for convenience, fmt.h defines the integer FMT_ULONG to be big enough to contain every possible fmt_uint output plus \0.
so like. if you're allocating a buffer and you're not sure how much room, FMT_ULONG has your back. she's the friend who always brings snacks for everyone π
π SEE ALSO π
scan_uint(3)β the reverse bestie, reads them back infmt_uint(3)β her sister, minus the zero padding
that's the whole page, babe. every flag, every byte, every \0-that-isn't-there. go forth and pad π
this has been fmt_uint0(3) from the Library Functions Manual β stay padded, stay iconic, and remember: she does not append \0, so you append \0. mwah ππ§π
π¦ where this page comes from
- alpine 3.24: libowfat-doc 0.34-r0 Β· GPL-2.0-only
- debian bookworm: libowfat-dev 0.32-4 Β· GPL-2.0-only
- debian trixie: libowfat-dev 0.32-5 Β· GPL-2.0-only
- nixos 26.05: libowfat 0.34
- nixpkgs unstable: libowfat 0.34
- opensuse-leap 16.0: libowfat-devel 0.33-bp160.1.11 Β· GPL-2.0-only
- opensuse-leap 16.0: libowfat-devel 0.33-bp160.1.11 Β· GPL-2.0-only
- opensuse-leap 16.0: libowfat-devel 0.33-bp160.1.11 Β· GPL-2.0-only
- opensuse-leap 16.0: libowfat-devel 0.33-bp160.1.11 Β· GPL-2.0-only
- ubuntu noble: libowfat-dev 0.32-4.1build1 Β· GPL-2.0-only
- ubuntu questing: libowfat-dev 0.32-5
- ubuntu resolute: libowfat-dev 0.34-2 Β· GPL-2.0-only
- ubuntu stonking: libowfat-dev 0.34-2 Β· GPL-2.0-only
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms