NE_BUFFER_APPEND(3)
β¨ NE_BUFFER_APPEND β¨ (bestie's guide to the neon API reference)
okay so. you know how strings in C are like, the most high-maintenance thing ever? π
this whole little family of functions is here to make appending to a ne_buffer not a whole saga. no cap.
π NAME π
ne_buffer_append, ne_buffer_zappend, ne_buffer_qappend, ne_buffer_concat, ne_buffer_snprintf β append data to a string buffer π«Ά
π¦ SYNOPSIS π¦
#include <ne_string.h>
void ne_buffer_append(ne_buffer *buf, const char *string, size_t len);
void ne_buffer_zappend(ne_buffer *buf, const char *string);
void ne_buffer_qappend(ne_buffer *buf, const char *string, size_t len);
void ne_buffer_concat(ne_buffer *buf, ...);
size_t ne_buffer_snprintf(ne_buffer *buf, size_t max,
const char *format, ...);
πΈ DESCRIPTION πΈ
the basics β ne_buffer_append & ne_buffer_zappend π
these two literally just stick a string onto the end of a buffer, and grow the buffer as needed. main character energy, they handle it.
the len you pass to ne_buffer_append is the length of the string you're appending β and heads up, there must be no NUL terminator in the first len bytes of that string. like, fr, don't do it.
ne_buffer_zappend is the chill one: you just hand it a NUL-terminated string. easy.
the safety girlie β ne_buffer_qappend π₯
ne_buffer_qappend is basically ne_buffer_append's cautious older sister. same vibe, except any non-ASCII characters or ASCII control characters get escaped using C-style hex escaping. π
for example, the C string "foo<TAB>bar" β where TAB means ASCII character 9 β gets appended as "foo\x09bar". any NUL bytes inside the length you specified get escaped too, bestie.
why do you care? because this is the function that makes strings from untrusted sources safe for logging or for showing in a user interface. it's giving responsible queen behaviour. π§
the group project β ne_buffer_concat π
ne_buffer_concat takes a variable-length argument list. every single argument has to be a char * pointer to a NUL-terminated string, and you must pass a NULL pointer as the last argument to mark the end of the list β that's the "we're done here" signal, don't forget it. β
the strings get appended to the buffer in the order you give them. and ngl, none of the strings passed to ne_buffer_concat are modified β they stay exactly as they were. π«Ά
the formatted one β ne_buffer_snprintf πΈ
ne_buffer_snprintf behaves like snprintf, appending the output string formatted according to the format parameter. at most max bytes are written, including the trailing NUL terminator. yes, including. count it. π
π RETURN VALUE π
only ne_buffer_snprintf is out here returning anything: it returns the number of bytes appended, excluding the trailing NUL terminator. that's it. that's the whole vibe check. β¨
π EXAMPLES π
this little cutie right here outputs "Hello, world. And goodbye." β iconic.
ne_buffer *buf = ne_buffer_create();
ne_buffer_zappend(buf, "Hello");
ne_buffer_concat(buf, ", world. ", "And ", NULL);
ne_buffer_snprintf(buf, 10, "%s.", "goodbye");
puts(buf->data);
ne_buffer_destroy(buf);
π SEE ALSO π
π COPYRIGHT π
Copyright Β© 2001-2026 Joe Orton
and that's the whole page, bestie π this was neon, dated 03/20/2026, and honestly? she ate. periodt. πβ¨π¦
π¦ where this page comes from
- arch rolling: neon 0.37.1-1 Β· LGPL-2.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms