KHTML_PUTS(3)
π KHTML_PUTS(3) β like, the kcgihtml string-putting era β¨
okay bestie, so this is a page from the Library Functions Manual and it's about khtml_puts β literally the moment your C code gets to say words out loud on a web page π«Ά
πΈ NAME πΈ
khtml_puts β put string content for kcgihtml. that's it, that's the whole vibe π
π LIBRARY π
library βlibkcgihtmlβ β yes queen, that's the one π
β¨ SYNOPSIS β¨
#include <sys/types.h>
#include <stdarg.h>
#include <stdint.h>
#include <kcgi.h>
#include <kcgihtml.h>
enum kcgi_err
khtml_puts(struct khtmlreq *req, const char *cp);
π¦ DESCRIPTION π¦
So basically it writes a NUL-terminated string cp into a context req β and req has to be one you already initialised with khtml_open(3), no shortcuts bestie π
Here's the cute part: if cp is NULL, it literally does nothing and returns success. iconic. no drama, no crash, just vibes π
All of the content gets HTML escaped β so for example, the left-angle bracket "<" gets rendered as "<". ngl that's the whole point, you can't have your user string breaking out and becoming markup, that would be a main character moment of the bad kind π
And heads up: it does not append a newline like puts(3) does. no cap, different function, different rules β
π₯ RETURN VALUES π₯
Returns an enum kcgi_err telling you the error state. here's the whole lineup:
KCGI_OKβ success!! not an error, we're thriving πKCGI_ENOMEMβ internal memory allocation failure π the allocator said noKCGI_HUPβ the output connection has been 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 indicates thatkhttp_body(3)did not return with success or was not invoked. for FastCGI connections, you should release the current connection withkhttp_free(3)and reenter the parse loop πKCGI_SYSTEMβ internal system error writing to the output stream π
lowkey memorise those last two, they both tell you to khttp_free(3) and reenter the parse loop. fr fr, same instructions, different causes.
π 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 (do as the manpage says, not as the manpage does, bestie π):
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_puts(&req, "Hello, world.");
khtml_close(&req);
look at that. "Hello, world." β the original hello world, the blueprint, the moment πβ¨
π 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 a legend π«Ά
π§ cute little sign-off π§
this page came from Debian, its version stamp is $Mdocdate$, and it's filed under KHTML_PUTS(3). periodt. now go escape some strings, 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