C Collections

chttpserver · Section 3

chttpsvr_resp_printf

chttpsvr_resp_printf - format and append a printf-style string to the response body

C Collections (libccollections, -lccollections)

#include <ccollections/chttpserver.h>
 
ccol_retval chttpsvr_resp_printf(chttpsvr_resp *resp,
                                    const char *fmt, ...);

Formats fmt and the variadic arguments with the printf rules and
appends the result to the response body.  The effect is the same as
formatting into a temporary string and passing that string to
chttpsvr_resp_write_str.  Short output is built in a small stack
buffer inside the library, and longer output in a temporary heap
allocation of exactly the size of the formatted text, which is freed
before the function returns.  Each call appends to the same response
body, as chttpsvr_resp_write_str does.
 
The format string is checked by the compiler through the GCC
attribute __attribute__((format(printf, 2, 3))).

ccol_success           - The formatted output was appended to the
                         body.
ccol_invalid_args      - resp or fmt is NULL, or the underlying
                          vsnprintf call reports an encoding error.
ccol_not_enough_memory - The body buffer or the temporary heap buffer
                          could not be allocated.

chttpsvr_resp_write(3), chttpsvr_resp_write_str(3), chttpsvr_resp_write_json(3)