Extract value of "key=VALUE" from a structured log line. */
| 24 | |
| 25 | /* Extract value of "key=VALUE" from a structured log line. */ |
| 26 | static const char *extract_kv(const char *line, const char *key, char *buf, int buf_len) { |
| 27 | if (!line || !key || !buf || buf_len <= 0) { |
| 28 | return NULL; |
| 29 | } |
| 30 | size_t klen = strlen(key); |
| 31 | const char *p = line; |
| 32 | while (*p) { |
| 33 | if ((p == line || p[-SKIP_ONE] == ' ') && strncmp(p, key, klen) == 0 && p[klen] == '=') { |
| 34 | const char *val = p + klen + SKIP_ONE; |
| 35 | int i = 0; |
| 36 | while (val[i] && val[i] != ' ' && i < buf_len - SKIP_ONE) { |
| 37 | buf[i] = val[i]; |
| 38 | i++; |
| 39 | } |
| 40 | buf[i] = '\0'; |
| 41 | return buf; |
| 42 | } |
| 43 | p++; |
| 44 | } |
| 45 | return NULL; |
| 46 | } |
| 47 | |
| 48 | void cbm_progress_sink_init(FILE *out) { |
| 49 | s_out = out ? out : stderr; |
no outgoing calls
no test coverage detected