KHTML_ELEM(3)
π
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: ifelemis a βvoidβ element (self-closing, likeKELEM_LINK) orKELEM_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 withkhttp_free(3)and reenter the parse loop. π«ΆKCGI_FORMβ the connection is still expecting headers withkhttp_head(3). this one meanskhttp_body(3)didn't return with success, or it just wasn't invoked at all. also: for FastCGI connections, release the current connection withkhttp_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
- Copyright (c) 2020 Kristaps Dzonsons <kristaps@bsd.lv>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms