KHTML_PUTC(3)

πŸ“¦ version 1.0.1, in alpine 3.24

πŸ’… 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 "&lt;". 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 with khttp_free(3) and reenter the parse loop πŸ”
  • KCGI_FORM β€” The connection is still expecting headers with khttp_head(3). This means khttp_body(3) did not return with success, or was, like, never invoked at all πŸ™ˆ Again, for FastCGI connections: release the current connection with khttp_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
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms