fmt_uint0(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_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 than n, she just writes the whole thing anyway. n is 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 πŸ‘‘


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 πŸ“πŸ§šπŸ’–