diff options
author | pommicket <pommicket@gmail.com> | 2022-12-22 16:38:32 -0500 |
---|---|---|
committer | pommicket <pommicket@gmail.com> | 2022-12-22 16:38:32 -0500 |
commit | 23e138019964662b4e847770eeda2bb5d3130f7a (patch) | |
tree | c92d36b878d26594cab5a35110dff6ad546d6a3d /json.c | |
parent | 6bb4da5fab94d2ed3d093b996674fd1cc28eda2f (diff) |
better write_string
Diffstat (limited to 'json.c')
-rw-r--r-- | json.c | 5 |
1 files changed, 4 insertions, 1 deletions
@@ -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" |