KHTML_WRITE(3)
π 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 "<". 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 withkhttp_free(3)and the parse loop reentered. πKCGI_FORMβ The connection is still expecting headers withkhttp_head(3). Indicates thatkhttp_body(3)did not return with success or was not invoked. For FastCGI connections, the current connection should be released withkhttp_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
- 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