Skip to content

log_printf: Restructured log_printf for wrapping #7567

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions cores/esp32/esp32-hal-uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand All @@ -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++){
Expand Down