libsrt, sds, SafeStr... How many times will this problem be solved independently before something like this makes it into the standard lib? Libsrt looks nice, but if you can't use it to interface to libraries that use the same types, you're still futzing around with char buffers.
What does Kore use? libsrt? Let's have a look at how you're supposed to program a web app in its examples:
int
serve_file_upload(struct http_request *req)
{
int r;
u_int8_t *d;
struct kore_buf *b;
u_int32_t len;
char *name, buf[BUFSIZ];
b = kore_buf_create(asset_len_upload_html);
kore_buf_append(b, asset_upload_html, asset_len_upload_html);
if (req->method == HTTP_METHOD_POST) {
http_populate_multipart_form(req, &r);
if (http_argument_get_string("firstname", &name, &len)) {
kore_buf_replace_string(b, "$firstname$", name, len);
} else {
kore_buf_replace_string(b, "$firstname$", NULL, 0);
}
if (http_file_lookup(req, "file", &name, &d, &len)) {
(void)snprintf(buf, sizeof(buf),
"%s is %d bytes", name, len);
kore_buf_replace_string(b,
"$upload$", buf, strlen(buf));
} else {
kore_buf_replace_string(b, "$upload$", NULL, 0);
}
} else {
kore_buf_replace_string(b, "$upload$", NULL, 0);
kore_buf_replace_string(b, "$firstname$", NULL, 0);
}
d = kore_buf_release(b, &len);
http_response_header(req, "content-type", "text/html");
http_response(req, 200, d, len);
kore_mem_free(d);
return (KORE_RESULT_OK);
}
Uh oh. So Kore invented yet another safe string/buf type? Why didn't they use libsrt? What's all this kore_buf stuff?
Strings in C are NOT a solved problem. They're a hot mess.