kfsw-services/src/parameter/libparam_print.c
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* This file provides the replacement for the forced-include redirect. */ | ||
| 2 | #undef printf | ||
| 3 | |||
| 4 | #include <stdarg.h> | ||
| 5 | |||
| 6 | #include <zephyr/sys/printk.h> | ||
| 7 | |||
| 8 | #define KFSW_LOG_MODULE KFSW_LOG_MODULE_PARAM | ||
| 9 | #include <kfsw/services/log.h> | ||
| 10 | |||
| 11 | /* | ||
| 12 | * libparam prints diagnostics with printf. The build redirects them here, and | ||
| 13 | * they become debug log lines in the parameter module. | ||
| 14 | */ | ||
| 15 | |||
| 16 | ✗ | int kfsw_libparam_printf(const char *format, ...) | |
| 17 | { | ||
| 18 | char message[128]; | ||
| 19 | va_list args; | ||
| 20 | int written; | ||
| 21 | |||
| 22 | ✗ | va_start(args, format); | |
| 23 | ✗ | written = vsnprintk(message, sizeof(message), format, args); | |
| 24 | ✗ | va_end(args); | |
| 25 | |||
| 26 | /* libparam ends most of its lines itself; the log adds its own. */ | ||
| 27 | ✗ | for (size_t index = 0U; message[index] != '\0'; index++) { | |
| 28 | ✗ | if ((message[index] == '\n') || (message[index] == '\r')) { | |
| 29 | ✗ | message[index] = '\0'; | |
| 30 | ✗ | break; | |
| 31 | } | ||
| 32 | } | ||
| 33 | |||
| 34 | kfsw_log_debug("%s", message); | ||
| 35 | ✗ | return written; | |
| 36 | } | ||
| 37 |