KHTML_PUTS(3)

πŸ“¦ version 1.0.1, in alpine 3.24

πŸ’… 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 "&lt;". 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 no
  • KCGI_HUP β€” the output connection has been terminated. for FastCGI connections, you should release the current connection with khttp_free(3) and reenter the parse loop 🫢
  • KCGI_FORM β€” the connection is still expecting headers with khttp_head(3). this indicates that khttp_body(3) did not return with success or was not invoked. for FastCGI connections, you should release the current connection with khttp_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
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms