summaryrefslogtreecommitdiff
path: root/json.c
diff options
context:
space:
mode:
authorpommicket <pommicket@gmail.com>2022-12-22 16:38:32 -0500
committerpommicket <pommicket@gmail.com>2022-12-22 16:38:32 -0500
commit23e138019964662b4e847770eeda2bb5d3130f7a (patch)
treec92d36b878d26594cab5a35110dff6ad546d6a3d /json.c
parent6bb4da5fab94d2ed3d093b996674fd1cc28eda2f (diff)
better write_string
Diffstat (limited to 'json.c')
-rw-r--r--json.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/json.c b/json.c
index 5d83b89..c11d907 100644
--- a/json.c
+++ b/json.c
@@ -605,7 +605,9 @@ void json_debug_print(const JSON *json) {
// e.g. converts "Hello\nworld" to "Hello\\nworld"
// if out_sz is at least 2 * strlen(str) + 1, the string will fit.
-void json_escape_to(char *out, size_t out_sz, const char *in) {
+// returns the number of bytes actually written, not including the null terminator.
+size_t json_escape_to(char *out, size_t out_sz, const char *in) {
+ char *start = out;
char *end = out + out_sz;
assert(out_sz);
@@ -653,6 +655,7 @@ void json_escape_to(char *out, size_t out_sz, const char *in) {
}
brk:
*out = '\0';
+ return (size_t)(out - start);
}
// e.g. converts "Hello\nworld" to "Hello\\nworld"