log_printf: Restructured log_printf for wrapping (#7567)

This commit is contained in:
Sanket Wadekar 2022-12-12 18:31:55 +05:30 committed by GitHub
parent 3af0b44f38
commit 165d62472a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -496,21 +496,18 @@ int uartGetDebug()
return s_uart_debug_nr;
}
int log_printf(const char *format, ...)
int log_printfv(const char *format, va_list arg)
{
static char loc_buf[64];
char * temp = loc_buf;
int len;
va_list arg;
va_list copy;
va_start(arg, format);
va_copy(copy, arg);
len = vsnprintf(NULL, 0, format, copy);
va_end(copy);
if(len >= sizeof(loc_buf)){
temp = (char*)malloc(len+1);
if(temp == NULL) {
va_end(arg);
return 0;
}
}
@ -528,13 +525,22 @@ int log_printf(const char *format, ...)
xSemaphoreGive(_uart_bus_array[s_uart_debug_nr].lock);
}
#endif
va_end(arg);
if(len >= sizeof(loc_buf)){
free(temp);
}
return len;
}
int log_printf(const char *format, ...)
{
int len;
va_list arg;
va_start(arg, format);
len = log_printfv(format, arg);
va_end(arg);
return len;
}
static void log_print_buf_line(const uint8_t *b, size_t len, size_t total_len){
for(size_t i = 0; i<len; i++){