KJSON_PUTINT(3)
π KJSON_PUTINT(3) π
okay so this is the kcgijson integer-writing page β the whole squad is kjson_putint, kjson_putintp, kjson_putintstr, kjson_putintstrp, and kjson_string_putint. bestie, they all just put integers π
πΈ LIBRARY πΈ
it lives in the library "libkcgijson" β that's the one, no cap π«Ά
β¨ SYNOPSIS β¨
#include <sys/types.h>
#include <stdarg.h>
#include <stdint.h>
#include <kcgi.h>
#include <kcgijson.h>
enum kcgi_err
kjson_putint(struct kjsonreq *req, int64_t v);
enum kcgi_err
kjson_putintp(struct kjsonreq *req, const char *name, int64_t v);
enum kcgi_err
kjson_string_putint(struct kjsonreq *req, int64_t v);
enum kcgi_err
kjson_putintstr(struct kjsonreq *r, int64_t v);
enum kcgi_err
kjson_putintstrp(struct kjsonreq *r, const char *name, int64_t v);
π DESCRIPTION π
so basically you're writing a 64-bit integer v into a context req that you already initialised with khtml_open(3). it formats the value as [-]?[0-9]+. slay, that's it β¨
now the vibe check on which function is which scope, because using the wrong one is literally a whole thing (see KCGI_WRITER below π):
kjson_putint()andkjson_putintstr()β for array scopeskjson_putintp()andkjson_putintstrp()β for objectskjson_string_putint()β for open strings
β οΈ okay this part matters, bestie: JavaScript is limited to 53 bits, so it's possible that integers may be truncated with kjson_putint() and family. π not a drill!
the alternative forms, kjson_putintstr() and kjson_putintstrp(), emit the value within a string. why? so JavaScript can parse the integer and handle overflow and underflow explicitly. main character energy honestly π
and one more little detail π β passing a NULL value to name for kjson_putintp() or kjson_putintstrp() is equivalent to calling kjson_putint() or kjson_putintstr(), respectively. cute, right?
π₯ RETURN VALUES π₯
returns an enum kcgi_err indicating the error state. here's the whole roster:
KCGI_OKβ success (not an error) πKCGI_ENOMEMβ internal memory allocation failure πKCGI_HUPβ the output connection has been terminated. for FastCGI connections, the current connection should be released withkhttp_free(3)and parse loop reentered.KCGI_FORMβ the connection is still expecting headers withkhttp_head(3). 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 parse loop reentered.KCGI_SYSTEMβ internal system error writing to the output stream π¬KCGI_WRITERβ the incorrect form was used for the current scope, for example, an array-type write within an object. (yes, this is the one from the vibe check above π)
π¦ EXAMPLES π¦
the following outputs a simple JSON document. it assumes r is a struct kreq pointer. for brevity, it does not do any error checking.
khttp_head(r, kresps[KRESP_STATUS],
"%s", khttps[KHTTP_200]);
khttp_head(r, kresps[KRESP_CONTENT_TYPE],
"%s", kmimetypes[KMIME_APP_JSON]);
khttp_body(r);
kjson_open(&req, r);
kjson_obj_open(&req);
kjson_putintp(&req, "bar", 12345);
kjson_arrayp_open(&req, "baz");
kjson_putint(&req, 1)); /* 1 */
kjson_putintstr(&req, 1)); /* "1" */
kjson_close(&req);
see how kjson_putint(&req, 1) gives you the raw 1 and kjson_putintstr(&req, 1) gives you the stringy "1"? iconic difference, iykyk π
π SEE ALSO π
kcgijson(3) β go read that one too, fr fr π«Ά
π AUTHORS π
written by Kristaps Dzonsons <kristaps@bsd.lv>. legend behavior honestly π
and that's the whole page, bestie! this lil beauty comes to you from Debian, rocking the $Mdocdate$ date stamp, and it's filed under KJSON_PUTINT(3) in the manual. go forth and put some integers β¨ππΈ
π¦ 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