fmt_pad(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

✨ NAME ✨

fmt_pad β€” pad a string with spaces. that's it, that's the whole job, and she does it flawlessly πŸ’…


πŸŽ€ SYNTAX πŸŽ€

bestie, first you gotta invite her in:

#include <libowfat/fmt.h>

then the whole squad shows up like:

size_t fmt_pad(char *dest, const char *source,
      size_t srclen, size_t padlen,
      size_t maxlen);

πŸ¦‹ DESCRIPTION πŸ¦‹

okay so picture this: you want your string to have main character energy and take up a lil more space than it naturally does. that's literally what fmt_pad is for 🫢

here's the tea. fmt_pad writes padlen-srclen spaces β€” only if that number is positive, so if you're out here asking for negative padding, nothing happens, no drama β€” and then it writes srclen characters from source. spaces first, string second, in that order, no cap.

now, the girl is disciplined. she truncates the output only if the length would exceed maxlen. that's the only reason she'll ever cut you off. respect.

and she returns the number of bytes she wrote. so you always know exactly how much she showed up for you.

πŸ’€ IMPORTANT: fmt_pad does not append \0. she is not null-terminating your string. she's not your therapist and she's not adding terminators. do that yourself, bestie, or you WILL be in your flop era.

and the iconic part β€” if dest equals FMT_LEN (i.e. is zero), fmt_pad returns the number of bytes it would have written. so you can vibe-check your sizing first, no actual writing, just a lil peek at what could've been. obsessed. ✨


πŸ‘‘ SEE ALSO πŸ‘‘

the rest of the friend group, all equally iconic:


and that's the whole page, babe πŸŽ€ fmt_pad(3), straight out of the Library Functions Manual β€” no version, no date, just timeless excellence, as she deserves. go pad something. slay. πŸ’–πŸ¦‹