fmt_netstring(3)

πŸ’– fmt_netstring(3) πŸ’–

okay bestie, so this one lives in the Library Functions Manual and it's literally called fmt_netstring β€” say it with me, it's giving format a netstring. πŸŽ€


✨ NAME ✨

fmt_netstring β€” turn a raw memory buffer into a netstring πŸ¦‹


🌸 SYNTAX 🌸

#include <libowfat/fmt.h>

size_t fmt_netstring(char *dest,const char *source,
                      size_t len);

no cap, that's the whole signature πŸ’…


🌈 DESCRIPTION 🌈

so fmt_netstring takes a raw memory buffer and builds a netstring out of it, then hands you back the length. that's it. that's the job. iconic. πŸ‘‘

important: fmt_netstring does not append \0. like, it's not that kind of function, don't come for it. 🚫

and here's the lil trick that makes it so good β€” if dest equals FMT_LEN (i.e. it's zero), then fmt_netstring just returns the number of bytes it would have written. a little "just tell me how much room I need" moment. so thoughtful fr fr 🫢


πŸ’œ RETURN VALUE πŸ’œ

fmt_netstring returns the number of bytes written β€” or the number that would have been written, if the destination pointer was pointed at NULL. πŸ’«

but heads up bestie: if the input buffer is implausibly large, fmt_netstring returns 0 instead. not a vibe, but it's the rules. 😭


πŸ“ EXAMPLE πŸ“

the raw memory buffer "foo" would become the netstring "3:foo,"

✨ literally that simple ✨


🧚 SPEC 🧚

http://cr.yp.to/proto/netstrings.txt

go read the source of truth, iykyk πŸ“–


⭐ SEE ALSO ⭐


and that's the whole page, bestie!! this was page fmt_netstring(3) from the Library Functions Manual, and it slayed, periodt. πŸ’…βœ¨πŸŽ€