KHTML_PUTC(3)
π KHTML_PUTC β bestie edition π
Okay so real talk: this is a page from KHTML_PUTC(3), part of the Library Functions Manual, and it's literally about putting one single character on a web page. One. Character. At a time. Iconic behaviour honestly, no notes. π¦
β¨ NAME β¨
khtml_putc β put character content for kcgihtml, that's the whole job, that's the assignment, she ate π
π LIBRARY π
library βlibkcgihtmlβ β yes queen, that's the one, that's the shelf she lives on πΈ
π SYNOPSIS π
Like, you gotta include all of these first, no skipping, the compiler WILL know:
#include <sys/types.h>
#include <stdarg.h>
#include <stdint.h>
#include <kcgi.h>
#include <kcgihtml.h>
enum kcgi_err
khttp_putc(struct kreq *req, char c);
Not me pointing out that the function is called khttp_putc in the synopsis while the page is khtml_putcβ¦ iykyk, that's just how it is, don't come for me π₯
π DESCRIPTION π
So basically: khtml_putc writes a character c into a context req that you already opened up with khtml_open(3) (the original says "initialiswed", which is fr fr a typo, but the vibe is "initialised", we move π«Ά).
And here's the slay part β the character gets HTML escaped. So for example, the left-angle bracket "<" gets rendered as "<". Not me protecting your markup from chaos ππ
π RETURN VALUES π
She returns an enum kcgi_err, which is the error state β a little vibe check on how things went β
KCGI_OKβ Success, queen! This is not an error, it's the good ending πKCGI_ENOMEMβ Internal memory allocation failure. Memory said "no ma'am" πKCGI_HUPβ The output connection has been terminated. And heads up for FastCGI connections specifically: 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 meanskhttp_body(3)did not return with success, or was, like, never invoked at all π Again, for FastCGI connections: release the current connection withkhttp_free(3)and reenter the parse loop.KCGI_SYSTEMβ Internal system error writing to the output stream. The system is being a hater π€
π₯ EXAMPLES π₯
Okay so this outputs a simple HTML page. It assumes r is a struct kreq pointer, and for brevity it does zero error checking β we're living dangerously, we're main character energy, we're not checking a single return value π§
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_putc(&req, 'H');
khtml_putc(&req, 'i');
khtml_putc(&req, '!');
khtml_close(&req);
Notice how she built "Hi!" one character at a time like an absolute legend? That's the whole function doing its thing. 'H', 'i', '!', close, done. Iconic. No cap π
π¦ SEE ALSO π¦
kcgihtml(3)β go read that one too, bestie, it's the whole family π
π STANDARDS π
The referenced HTML5 standard is HTML5.2, and here's the link, copy it exactly: https://www.w3.org/TR/html52 β periodt π
π AUTHORS π
Written by Kristaps Dzonsons <kristaps@bsd.lv> β we stan a legend π«Ά
Okay that's the whole page!! And now for the cute sign-off: this lil masterpiece comes from the Debian package, versioned at $Mdocdate$, and it's the KHTML_PUTC(3) page, forever and always πβ¨π Go forth and put characters, bestie!! πΈπ¦π
π¦ 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