KHTML_ELEM(3)

πŸ“¦ version 1.0.1, in alpine 3.24

πŸ’… KHTML_ELEM(3) β€” the khtml_elem page, bestie edition

okay so real quick: this is a page from the Library Functions Manual for libkcgihtml, and the star of the show is khtml_elem. it opens element scopes. that's the whole vibe. let's get into it 🫢

πŸ“š LIBRARY

you'll find this in the library β€œlibkcgihtml” β€” that's the one you're linking against, no cap ✨

🌸 SYNOPSIS

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

enum kcgi_err
khtml_elem(struct khtmlreq *req, enum kelem elem);

like, include all five of those headers or your build is gonna be giving nothing but errors πŸ’€

✨ DESCRIPTION ✨

so what it does: it opens a new scope of element elem on the current element stack of req β€” and req is the one you already initialised with khtml_open(3). main character energy, honestly πŸ‘‘

and then you close those scopes with khtml_closeelem(3), khtml_closeto(3). or khtml_close(3). (yes, that period is in the original, i'm not touching it, iykyk πŸ™ˆ)

πŸ’‘ tiny but crucial detail: if elem is a β€œvoid” element (self-closing, like KELEM_LINK) or KELEM_DOCTYPE, the scope gets immediately closed β€” so like, no new scope gets opened at all. it does the thing and dips πŸ¦‹

πŸ”₯ RETURN VALUES

returns an enum kcgi_err telling you the error state. so like, the vibe check result πŸ’…

  • KCGI_OK β€” success!! not an error!! we love a win 🌈
  • KCGI_ENOMEM β€” internal memory allocation failure, and that includes hitting the maximum number of possible HTML scopes. yeah, there's a cap, and you found it 😭
  • KCGI_HUP β€” the output connection got terminated. for FastCGI connections, you should release the current connection with khttp_free(3) and reenter the parse loop. 🫢
  • KCGI_FORM β€” the connection is still expecting headers with khttp_head(3). this one means khttp_body(3) didn't return with success, or it just wasn't invoked at all. also: for FastCGI connections, release the current connection with khttp_free(3) and reenter the parse loop. same drill, different error πŸŽ€
  • KCGI_SYSTEM β€” internal system error while writing to the output stream. rough. πŸ’€

πŸŽ€ EXAMPLES πŸŽ€

this one outputs a simple HTML page. it assumes r is a struct kreq pointer. and for brevity β€” bestie, respect the brevity β€” it does no error checking whatsoever. iconic but dangerous πŸ™ˆ

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_HEAD);
khtml_elem(&req, KELEM_TITLE);
khtml_puts(&req, "Hello, world.");
khtml_close(&req);

look at all those khtml_elem calls stacking up β€” that's a stack, bestie, it's literally in the name 🧚

πŸ‘€ SEE ALSO

⭐ STANDARDS

the referenced HTML5 standard is HTML5.2 at https://www.w3.org/TR/html52 β€” go read it if you're feeling academic πŸ’œ

πŸ‘‘ AUTHORS

written by Kristaps Dzonsons <kristaps@bsd.lv>. king behavior, fr fr 🌸


and that's the page!! πŸ’– this build came from Debian, dated $Mdocdate$, and it's page KHTML_ELEM(3) of the Library Functions Manual β€” slay, go open some scopes πŸ¦‹βœ¨πŸŽ€

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