diff --git a/examples/client/client_example.c b/examples/client/client_example.c index e575226..6960bac 100644 --- a/examples/client/client_example.c +++ b/examples/client/client_example.c @@ -43,7 +43,7 @@ int main(int argc, char **argv) { } printf("Status: %d\n", result->status); - printf("Body: %.*s\n", (int)result->body.len, result->body.ptr); + printf("Body: %.*s\n", HTTP_UNPACK(result->body)); http_request_free(reqs[i-1]); } diff --git a/examples/client/web_crawler.c b/examples/client/web_crawler.c index b106ae7..7d047e1 100644 --- a/examples/client/web_crawler.c +++ b/examples/client/web_crawler.c @@ -173,11 +173,11 @@ int main(int argc, char **argv) if (url.len == 0) break; if (is_already_crawled(url)) { - printf("Ignoring " RED "%.*s" RST "\n", (int) url.len, url.ptr); + printf("Ignoring " RED "%.*s" RST "\n", HTTP_UNPACK(url)); continue; } - printf("Fetching " GRN "%.*s" RST "\n", (int) url.len, url.ptr); + printf("Fetching " GRN "%.*s" RST "\n", HTTP_UNPACK(url)); add_to_crawled_list(url); HTTP_RequestHandle req; diff --git a/examples/server/000_http_server.c b/examples/server/000_http_server.c index ffee546..fb2ab08 100644 --- a/examples/server/000_http_server.c +++ b/examples/server/000_http_server.c @@ -48,7 +48,7 @@ int main(void) // sure to express the length when interacting with // libc: HTTP_String path = req->url.path; - printf("requested path [%.*s]\n", (int) path.len, path.ptr); + printf("requested path [%.*s]\n", HTTP_UNPACK(path)); // To find a specific header value, you can either // iterate over the [req->headers] array or use @@ -60,7 +60,7 @@ int main(void) } else { // Found HTTP_String value = req->headers[idx].value; - printf("Header has value [%.*s]\n", (int) value.len, value.ptr); + printf("Header has value [%.*s]\n", HTTP_UNPACK(value)); } // To create a response, you will need to specify diff --git a/tests/test.c b/tests/test.c index 0737065..76f04df 100644 --- a/tests/test.c +++ b/tests/test.c @@ -35,10 +35,7 @@ void testeq_engstate(HTTP_EngineState l, HTTP_EngineState r, HTTP_String uneval_ { if (l != r) { printf("Test failed at %s:%d\n", file, line); - printf(" TEST_EQ(%.*s, %.*s) -> TEST_EQ(%s, %s)\n", - (int) uneval_l.len, uneval_l.ptr, - (int) uneval_r.len, uneval_r.ptr, - statestr(l), statestr(r)); + printf(" TEST_EQ(%.*s, %.*s) -> TEST_EQ(%s, %s)\n", HTTP_UNPACK(uneval_l), HTTP_UNPACK(uneval_r), statestr(l), statestr(r)); abort(); } } @@ -47,10 +44,7 @@ void testeq_int(int l, int r, HTTP_String uneval_l, HTTP_String uneval_r, const { if (l != r) { printf("Test failed at %s:%d\n", file, line); - printf(" TEST_EQ(%.*s, %.*s) -> TEST_EQ(%d, %d)\n", - (int) uneval_l.len, uneval_l.ptr, - (int) uneval_r.len, uneval_r.ptr, - l, r); + printf(" TEST_EQ(%.*s, %.*s) -> TEST_EQ(%d, %d)\n", HTTP_UNPACK(uneval_l), HTTP_UNPACK(uneval_r), l, r); abort(); } } @@ -59,11 +53,7 @@ void testeq_str(HTTP_String l, HTTP_String r, HTTP_String uneval_l, HTTP_String { if (!http_streq(l, r)) { printf("Test failed at %s:%d\n", file, line); - printf(" TEST_EQ(\"%.*s\", \"%.*s\") -> TEST_EQ(%.*s, %.*s)\n", - (int) uneval_l.len, uneval_l.ptr, - (int) uneval_r.len, uneval_r.ptr, - (int) l.len, l.ptr, - (int) r.len, r.ptr); + printf(" TEST_EQ(\"%.*s\", \"%.*s\") -> TEST_EQ(%.*s, %.*s)\n", HTTP_UNPACK(uneval_l), HTTP_UNPACK(uneval_r), HTTP_UNPACK(l), HTTP_UNPACK(r)); abort(); } }