KCGI_BUF_PRINTF(3)

πŸ“¦ version 1.0.1, in alpine 3.24

πŸ’… KCGI_BUF_PRINTF πŸ’…

okay so this is a page from the Library Functions Manual, section 3, and yes bestie the title says KCGI_BUF_PRINTF β€” hold that thought, we'll get to the synopsis 😭


✨ NAME ✨

kcgi_buf_printf β€” put variable content into a kcgi buffer 🫢


πŸ“š LIBRARY πŸ“š

library β€œlibkcgi”


πŸŽ€ SYNOPSIS πŸŽ€

#include <sys/types.h>
#include <stdarg.h>
#include <stdint.h>
#include <kcgi.h>

enum kcgi_err
kcgi_buf_puts(struct kcgi_buf *buf, const char *fmt, ...);

ngl, the function in the synopsis is literally spelled kcgi_buf_puts and not kcgi_buf_printf. That's what's on the page, so that's what you get β€” no editing the icon, periodt. πŸ’…


🌸 DESCRIPTION 🌸

So what does it do? It appends output to a buffer buf, formatting it according to the given fmt. The format works like printf(3) β€” same energy, same vibes, you already know her. ✨

⚠️ real talk: buffers have to be initialised to zero with memset(3) before you use them the first time. Not optional, bestie. Zero it out or it's giving uninitialised chaos. πŸ’€

πŸ¦‹ RETURN VALUES πŸ¦‹

It returns an enum kcgi_err telling you the error state. Here's the whole cast of characters, no cap:

  • KCGI_OK β€” success! not an error, we love a happy ending πŸ’–
  • KCGI_ENOMEM β€” internal memory allocation failure 😭 the malloc said no
  • KCGI_HUP β€” the output connection has been terminated. For FastCGI connections, the current connection should be released with khttp_free(3) and the parse loop reentered πŸ”₯
  • KCGI_FORM β€” the connection is still expecting headers with khttp_head(3). This one indicates that khttp_body(3) did not return with success or was not invoked at all πŸ™ˆ. For FastCGI connections, the current connection should be released with khttp_free(3) and the parse loop reentered.
  • KCGI_SYSTEM β€” internal system error writing to the output stream πŸ’€

🌈 EXAMPLES 🌈

okay this example creates a simple NUL-terminated buffer and outputs its contents. It does not perform any error checking β€” main character energy, honestly, but don't be like this in prod 🫢

struct kcgi_buf buf;

memset(&buf, 0, sizeof(struct kcgi_buf));
kcgi_buf_printf(&buf, "number %d", 1);
puts(buf.buf); /* Emits "number 1" */
free(buf.buf);

ate. ✨ (and then free(buf.buf), because we're responsible queens πŸ‘‘)


πŸ‘€ SEE ALSO πŸ‘€

kcgi_buf_putc(3), kcgi_buf_puts(3), kcgi_buf_write(3) β€” the whole squad, go say hi πŸ’œ


🧚 AUTHORS 🧚

Written by Kristaps Dzonsons <kristaps@bsd.lv>.


that's the whole page bestie!! and for the sign-off β€” this one ships from Debian, stamped $Mdocdate$, and the footer names her right back: KCGI_BUF_PRINTF(3). slay πŸ’…πŸŽ€πŸ’–

πŸ“¦ where this page comes from
  • alpine 3.24: kcgi-doc 1.0.1-r0 Β· ISC
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms