| 411 | static void http_appendf(char *buf, size_t bufsz, int *pos, const char *fmt, ...) |
| 412 | __attribute__((format(printf, 4, 5))); |
| 413 | static void http_appendf(char *buf, size_t bufsz, int *pos, const char *fmt, ...) { |
| 414 | if (*pos < 0) { |
| 415 | return; |
| 416 | } |
| 417 | if ((size_t)*pos >= bufsz) { |
| 418 | *pos = (int)bufsz; |
| 419 | return; |
| 420 | } |
| 421 | va_list ap; |
| 422 | va_start(ap, fmt); |
| 423 | int n = vsnprintf(buf + *pos, bufsz - (size_t)*pos, fmt, ap); |
| 424 | va_end(ap); |
| 425 | if (n < 0) { |
| 426 | return; |
| 427 | } |
| 428 | if ((size_t)n >= bufsz - (size_t)*pos) { |
| 429 | *pos = (int)bufsz; |
| 430 | } else { |
| 431 | *pos += n; |
| 432 | } |
| 433 | } |
| 434 | |
| 435 | /* GET /api/logs?lines=N — returns last N log lines */ |
| 436 | static void handle_logs(cbm_http_conn_t *c, const cbm_http_req_t *req) { |
no outgoing calls
no test coverage detected