From 39db14d75e612a25cf8d3478d86c7fff9a680b66 Mon Sep 17 00:00:00 2001 From: _VIFEXTech <1290176185@qq.com> Date: Sun, 30 Oct 2022 15:41:57 +0800 Subject: [PATCH] fix(printf): fix built-in snprintf cannot be disabled (#3776) Co-authored-by: pengyiqiang --- src/misc/lv_printf.c | 5 +++++ src/misc/lv_printf.h | 11 +++++++---- src/others/file_explorer/lv_file_explorer.c | 4 ++-- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/misc/lv_printf.c b/src/misc/lv_printf.c index 252dce936..7ec70d63e 100644 --- a/src/misc/lv_printf.c +++ b/src/misc/lv_printf.c @@ -33,6 +33,9 @@ /*Original repository: https://github.com/mpaland/printf*/ #include "lv_printf.h" + +#if LV_USE_BUILTIN_SNPRINTF + #include #define PRINTF_DISABLE_SUPPORT_FLOAT (!LV_SPRINTF_USE_FLOAT) @@ -872,3 +875,5 @@ int lv_vsnprintf_builtin(char * buffer, size_t count, const char * format, va_li { return _vsnprintf(_out_buffer, buffer, count, format, va); } + +#endif /*LV_USE_BUILTIN_SNPRINTF*/ diff --git a/src/misc/lv_printf.h b/src/misc/lv_printf.h index 9fc57206c..4d8adc229 100644 --- a/src/misc/lv_printf.h +++ b/src/misc/lv_printf.h @@ -62,9 +62,14 @@ extern "C" { #include "../lv_conf_internal.h" #include LV_STDIO_INCLUDE + +#define lv_snprintf LV_SNPRINTF +#define lv_vsnprintf LV_VSNPRINTF + +#if LV_USE_BUILTIN_SNPRINTF + #include #include - #include "lv_types.h" typedef struct { @@ -75,9 +80,7 @@ typedef struct { int lv_snprintf_builtin(char * buffer, size_t count, const char * format, ...); int lv_vsnprintf_builtin(char * buffer, size_t count, const char * format, va_list va); -#define lv_snprintf LV_SNPRINTF -#define lv_vsnprintf LV_VSNPRINTF - +#endif /*LV_USE_BUILTIN_SNPRINTF*/ #ifdef __cplusplus } /*extern "C"*/ diff --git a/src/others/file_explorer/lv_file_explorer.c b/src/others/file_explorer/lv_file_explorer.c index eba5d1857..c9b795b8d 100644 --- a/src/others/file_explorer/lv_file_explorer.c +++ b/src/others/file_explorer/lv_file_explorer.c @@ -502,11 +502,11 @@ static void browser_file_event_handler(lv_event_t * e) strip_ext(explorer->current_path); /*Remove the last '/' character*/ strip_ext(explorer->current_path); - lv_snprintf_builtin((char *)file_name, sizeof(file_name), "%s", explorer->current_path); + lv_snprintf((char *)file_name, sizeof(file_name), "%s", explorer->current_path); } else { if(strcmp(str_fn, "..") != 0) { - lv_snprintf_builtin((char *)file_name, sizeof(file_name), "%s%s", explorer->current_path, str_fn); + lv_snprintf((char *)file_name, sizeof(file_name), "%s%s", explorer->current_path, str_fn); } }