* @brief This function will print a formatted string on system console. * * @param fmt is the format parameters. * * @return The number of characters actually written to buffer. */
| 357 | * @return The number of characters actually written to buffer. |
| 358 | */ |
| 359 | rt_weak int rt_kprintf(const char *fmt, ...) |
| 360 | { |
| 361 | va_list args; |
| 362 | rt_size_t length = 0; |
| 363 | static char rt_log_buf[RT_CONSOLEBUF_SIZE]; |
| 364 | |
| 365 | va_start(args, fmt); |
| 366 | PRINTF_BUFFER_TAKE; |
| 367 | |
| 368 | /* the return value of vsnprintf is the number of bytes that would be |
| 369 | * written to buffer had if the size of the buffer been sufficiently |
| 370 | * large excluding the terminating null byte. If the output string |
| 371 | * would be larger than the rt_log_buf, we have to adjust the output |
| 372 | * length. */ |
| 373 | length = rt_vsnprintf(rt_log_buf, sizeof(rt_log_buf) - 1, fmt, args); |
| 374 | if (length > RT_CONSOLEBUF_SIZE - 1) |
| 375 | { |
| 376 | length = RT_CONSOLEBUF_SIZE - 1; |
| 377 | } |
| 378 | |
| 379 | _kputs(rt_log_buf, length); |
| 380 | |
| 381 | PRINTF_BUFFER_RELEASE; |
| 382 | va_end(args); |
| 383 | |
| 384 | return length; |
| 385 | } |
| 386 | RTM_EXPORT(rt_kprintf); |
| 387 | #endif /* RT_USING_CONSOLE */ |
| 388 |