Skip to content

Commit 86a1071

Browse files
authored
优化ULOG_OUTPUT_FLOAT,避免使用内置libc的vsnprintf函数 (#5632)
1 parent 38ed2a3 commit 86a1071

File tree

3 files changed

+2
-24
lines changed

3 files changed

+2
-24
lines changed

components/utilities/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ config RT_USING_ULOG
137137
config ULOG_OUTPUT_FLOAT
138138
bool "Enable float number support. It will using more thread stack."
139139
default n
140+
select PKG_USING_RT_VSNPRINTF_FULL
140141
help
141142
The default formater is using rt_vsnprint and it not supported float number.
142143
When enable this option then it will enable libc. The formater will change to vsnprint on libc.

components/utilities/ulog/syslog/syslog.c

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@
1414
#include <stdint.h>
1515
#include "syslog.h"
1616

17-
#ifdef ULOG_OUTPUT_FLOAT
18-
#include <stdio.h>
19-
#endif
20-
2117
/*
2218
* reference:
2319
* http://pubs.opengroup.org/onlinepubs/7908799/xsh/syslog.h.html
@@ -227,12 +223,7 @@ RT_WEAK rt_size_t syslog_formater(char *log_buf, int level, const char *tag, rt_
227223
#endif /* ULOG_OUTPUT_THREAD_NAME */
228224

229225
log_len += ulog_strcpy(log_len, log_buf + log_len, ": ");
230-
231-
#ifdef ULOG_OUTPUT_FLOAT
232-
fmt_result = vsnprintf(log_buf + log_len, ULOG_LINE_BUF_SIZE - log_len, format, args);
233-
#else
234226
fmt_result = rt_vsnprintf(log_buf + log_len, ULOG_LINE_BUF_SIZE - log_len, format, args);
235-
#endif /* ULOG_OUTPUT_FLOAT */
236227

237228
/* calculate log length */
238229
if ((log_len + fmt_result <= ULOG_LINE_BUF_SIZE) && (fmt_result > -1))

components/utilities/ulog/ulog.c

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@
1616
#include <syslog.h>
1717
#endif
1818

19-
#ifdef ULOG_OUTPUT_FLOAT
20-
#include <stdio.h>
21-
#endif
22-
2319
#ifdef ULOG_TIME_USING_TIMESTAMP
2420
#include <sys/time.h>
2521
#endif
@@ -367,12 +363,7 @@ RT_WEAK rt_size_t ulog_formater(char *log_buf, rt_uint32_t level, const char *ta
367363
#endif /* ULOG_OUTPUT_THREAD_NAME */
368364

369365
log_len += ulog_strcpy(log_len, log_buf + log_len, ": ");
370-
371-
#ifdef ULOG_OUTPUT_FLOAT
372-
fmt_result = vsnprintf(log_buf + log_len, ULOG_LINE_BUF_SIZE - log_len, format, args);
373-
#else
374366
fmt_result = rt_vsnprintf(log_buf + log_len, ULOG_LINE_BUF_SIZE - log_len, format, args);
375-
#endif /* ULOG_OUTPUT_FLOAT */
376367

377368
/* calculate log length */
378369
if ((log_len + fmt_result <= ULOG_LINE_BUF_SIZE) && (fmt_result > -1))
@@ -674,15 +665,10 @@ void ulog_raw(const char *format, ...)
674665

675666
/* lock output */
676667
output_lock();
668+
677669
/* args point to the first variable parameter */
678670
va_start(args, format);
679-
680-
#ifdef ULOG_OUTPUT_FLOAT
681-
fmt_result = vsnprintf(log_buf, ULOG_LINE_BUF_SIZE, format, args);
682-
#else
683671
fmt_result = rt_vsnprintf(log_buf, ULOG_LINE_BUF_SIZE, format, args);
684-
#endif /* ULOG_OUTPUT_FLOAT */
685-
686672
va_end(args);
687673

688674
/* calculate log length */

0 commit comments

Comments
 (0)