| 452 | static void http_appendf(char *buf, size_t bufsz, int *pos, const char *fmt, ...) |
| 453 | __attribute__((format(printf, 4, 5))); |
| 454 | static void http_appendf(char *buf, size_t bufsz, int *pos, const char *fmt, ...) { |
| 455 | if (*pos < 0) { |
| 456 | return; |
| 457 | } |
| 458 | if ((size_t)*pos >= bufsz) { |
| 459 | *pos = (int)bufsz; |
| 460 | return; |
| 461 | } |
| 462 | va_list ap; |
| 463 | va_start(ap, fmt); |
| 464 | int n = vsnprintf(buf + *pos, bufsz - (size_t)*pos, fmt, ap); |
| 465 | va_end(ap); |
| 466 | if (n < 0) { |
| 467 | return; |
| 468 | } |
| 469 | if ((size_t)n >= bufsz - (size_t)*pos) { |
| 470 | *pos = (int)bufsz; |
| 471 | } else { |
| 472 | *pos += n; |
| 473 | } |
| 474 | } |
| 475 | |
| 476 | /* GET /api/logs?lines=N — returns last N log lines */ |
| 477 | static void handle_logs(cbm_http_conn_t *c, const cbm_http_req_t *req) { |
no outgoing calls
no test coverage detected