KHTML_PRINTF(3)
π KHTML_PRINTF(3) β the manual page, bestie edition π
okay so real talk, this is KHTML_PRINTF(3) straight out of the Library Functions Manual, and it's literally the glow-up your HTML output needed. sit down, grab a strawberry drink π, and let's get into it.
β¨ NAME β¨
khtml_printf β put variable content for kcgihtml
like, it prints stuff. with variables. into your HTML. that's the whole vibe π
π LIBRARY π
library βlibkcgihtmlβ
π οΈ SYNOPSIS π οΈ
#include <sys/types.h>
#include <stdarg.h>
#include <stdint.h>
#include <kcgi.h>
#include <kcgihtml.h>
enum kcgi_err
khtml_printf(struct khtmlreq *req, const char *fmt, ...);
πΈ DESCRIPTION πΈ
So khtml_printf() writes output according to whatever fmt you hand it, into a context req that you already initialised with khtml_open(3). and the format? it's exactly as for printf(3). no cap, same energy π
and here's the cute part: if fmt is NULL, it literally does nothing and returns success. icon behaviour. main character energy. we love a function that respects the "never mind" moment π
all of the content is HTML escaped β like, for example, the left-angle bracket "<" gets rendered as "<". so nobody can sneak anything past it, periodt π
π₯ RETURN VALUES π₯
Returns an enum kcgi_err indicating the error state. so yeah, check it, bestie, don't just ignore it π
KCGI_OKβ Success (not an error). the slay outcome β¨KCGI_ENOMEMβ Internal memory allocation failure. the memory said no πKCGI_HUPβ The output connection has been terminated. and for FastCGI connections, the current connection should be released withkhttp_free(3)and the parse loop reentered. important!! π«ΆKCGI_FORMβ The connection is still expecting headers withkhttp_head(3). this one 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. same drill πKCGI_SYSTEMβ Internal system error writing to the output stream. the system is being a hater π
π EXAMPLES π
The following outputs a simple HTML page. it assumes r is a struct kreq pointer. and for brevity, it does not do any error checking β which, ngl, for real code you should probably do, but here we're keeping it cute and short π
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_printf(&req, "%s", "Hello, world.");
khtml_close(&req);
look at that. a whole page. we ate π½οΈβ¨
π SEE ALSO π
that's your bestie right there, go say hi π¦
π STANDARDS π
The referenced HTML5 standard is HTML5.2: https://www.w3.org/TR/html52
iykyk π
π AUTHORS π
Written by Kristaps Dzonsons <kristaps@bsd.lv>. thank you for your service, king π«‘π
and that's the whole page, bestie!! this lil drop came to you from Debian, dated $Mdocdate$, and it's KHTML_PRINTF(3) forever and always. go forth and escape your HTML π
πβ
π¦ 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