KHTML_WRITE(3)

πŸ“¦ version 1.0.1, in alpine 3.24

πŸ’… KHTML_WRITE πŸ’…

okay so bestie, we're talking about khtml_write from the KHTML_WRITE(3) manual page, and it lives in the library β€œlibkcgihtml” β€” yes that's the LIBRARY, and yes you should know it πŸ’–


✨ NAME ✨

khtml_write β€” put content data for kcgihtml πŸŽ€

πŸ¦‹ LIBRARY πŸ¦‹

library β€œlibkcgihtml”

🌸 SYNOPSIS 🌸

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

enum kcgi_err
khtml_write(const char *buf, size_t sz, void *arg);

πŸ’œ DESCRIPTION πŸ’œ

So basically, khtml_write writes binary data buf of length sz to a context arg, which is a struct khtmlreq that you initialised earlier with khtml_open(3) and then passed along as an opaque pointer. no cap, that's the whole vibe 🫢

And listen β€” if buf is NULL or sz is zero, it literally does nothing and just returns success. iconic behaviour, honestly. πŸ’…

okay but here's the main character detail: all of the content is HTML escaped. so like, the left-angle bracket "<" gets rendered as "&lt;". yes bestie, it's giving safety, it's giving slay ✨

πŸ‘‘ RETURN VALUES πŸ‘‘

Returns an enum kcgi_err that tells you the error state. let's go through them, iykyk πŸ”₯

  • KCGI_OK β€” Success (not an error). periodt πŸ’–
  • 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). Indicates that khttp_body(3) did not return with success or was not invoked. 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. 🧚
bestie please actually check these, the example below does not β€” it literally says so 😭

⭐ EXAMPLES ⭐

The following outputs a simple HTML page. It assumes r is a struct kreq pointer. For brevity, it does not do any error checking.

      khttp_head(r, kresps[KRESP_STATUS],
        "%s", khttps[KHTTP_200]);
      khttp_head(r, kresps[KRESP_CONTENT_TYPE],
        "%s", kmimetypes[KMIME_TEXT_HTML]);
      khttp_body(r);
      khtml_open(&req, r, 0);
      khtml_elem(&req, KELEM_DOCTYPE);
      khtml_elem(&req, KELEM_HTML);
      khtml_elem(&req, KELEM_BODY);
      khtml_elem(&req, KELEM_P);
      khtml_write("Hello, world.", 13, &req);
      khtml_close(&req);

like, that's the whole page. hello world but make it HTML πŸ’–

πŸŽ€ SEE ALSO πŸŽ€

🌈 STANDARDS 🌈

The referenced HTML5 standard is HTML5.2: https://www.w3.org/TR/html52.

πŸ“ AUTHORS πŸ“

Written by Kristaps Dzonsons <kristaps@bsd.lv>. we stan 🫢


✨ that's a wrap bestie ✨ this lil page is from Debian, dated $Mdocdate$, and it's filed under KHTML_WRITE(3) in the manual β€” go forth and escape your HTML, mwah πŸ’…πŸ’–

πŸ“¦ 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