fmt_strm_alloca(3)
π fmt_strm_alloca β bestie, it's literally the "smoosh a bunch of ASCII strings together on the stack" function π
okay so this page lives in the Library Functions Manual, and it's all about fmt_strm_alloca(3). Sit down, grab a boba, we're doing pointers π§β¨
πΈ NAME πΈ
fmt_strm_alloca β write multiple ASCII strings. that's it, that's the whole vibe. multiple strings, one destination, no cap π
π SYNTAX π
#include <libowfat/fmt.h>
char* fmt_strm_alloca(const char *source, ...);
look at her. one source pointer, and then ... which means "and however many more you want, queen" π«Ά
β¨ DESCRIPTION β¨
So here's the tea, bestie. fmt_strm_alloca copies all the leading nonzero bytes from source and from the following function arguments, drops them into a freshly allocated stack buffer, and hands you back a pointer to it. Boom. Done. Iconic behavior honestly π₯
Not me pausing to make sure you caught this: it copies leading nonzero bytes from source and from the following function arguments. All of them. Onto the stack. And returns the pointer. Okay slay.
And here's the one lil' difference you gotta remember:
fmt_strmdoes not append\0.fmt_strm_allocadoes append\0.
Unlink fmt_strm, fmt_strm_alloca does append \0. That's the whole distinction, and it matters, so don't mix them up π
β οΈ WARNING, and I mean it, this one's serious β οΈ Using variable size stack buffers is dangerous. Like, genuinely dangerous, not cute-dangerous. If the size of the buffer is larger than the hardware page size, then it can be used to skip over the guard page and cause memory corruption. Yeah. Memory corruption. That's the bad one. π fmt_strm_alloca has a built-in limit of 100000 bytes β that's your safety net, and it is not a suggestion. Use this only for trivially small strings. Trivially. Small. Periodt.
And if the strings do not come from a trusted place, or you are not sure they are small? bestie, please, prefer fmt_strm_malloc instead. It's the grown-up choice and it will not betray you π§π
π SEE ALSO π
go read those too, they're all part of the same little family π¦
and that's the whole page, bestie!! you made it to the end, I'm so proud of you π₯Ήπ This was fmt_strm_alloca(3) from the Library Functions Manual β yes, the footer is literally just the page name again, she's humble like that π
β¨
bye bestie, stay small, stay stack-safe, and always prefer fmt_strm_malloc when in doubt ππ
π¦ where this page comes from
- alpine 3.24: libowfat-doc 0.34-r0 Β· 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 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