[klibc] add rt_vsnprintf_std.c and rename RT_KLIBC_USING_VSNPRINTF_LONGLONG
This commit is contained in:
parent
e4b02a28f8
commit
8e10983c9b
|
@ -26,7 +26,7 @@
|
||||||
|
|
||||||
/* klibc optimization */
|
/* klibc optimization */
|
||||||
|
|
||||||
#define RT_KLIBC_USING_PRINTF_LONGLONG
|
#define RT_KLIBC_USING_VSNPRINTF_LONGLONG
|
||||||
/* end of klibc optimization */
|
/* end of klibc optimization */
|
||||||
#define RT_USING_DEBUG
|
#define RT_USING_DEBUG
|
||||||
#define RT_DEBUGING_ASSERT
|
#define RT_DEBUGING_ASSERT
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
|
|
||||||
/* klibc optimization */
|
/* klibc optimization */
|
||||||
|
|
||||||
#define RT_KLIBC_USING_PRINTF_LONGLONG
|
#define RT_KLIBC_USING_VSNPRINTF_LONGLONG
|
||||||
/* end of klibc optimization */
|
/* end of klibc optimization */
|
||||||
#define RT_USING_DEBUG
|
#define RT_USING_DEBUG
|
||||||
#define RT_DEBUGING_ASSERT
|
#define RT_DEBUGING_ASSERT
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
|
|
||||||
/* klibc optimization */
|
/* klibc optimization */
|
||||||
|
|
||||||
#define RT_KLIBC_USING_PRINTF_LONGLONG
|
#define RT_KLIBC_USING_VSNPRINTF_LONGLONG
|
||||||
/* end of klibc optimization */
|
/* end of klibc optimization */
|
||||||
#define RT_USING_DEBUG
|
#define RT_USING_DEBUG
|
||||||
#define RT_DEBUGING_ASSERT
|
#define RT_DEBUGING_ASSERT
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
|
|
||||||
/* klibc optimization */
|
/* klibc optimization */
|
||||||
|
|
||||||
#define RT_KLIBC_USING_PRINTF_LONGLONG
|
#define RT_KLIBC_USING_VSNPRINTF_LONGLONG
|
||||||
/* end of klibc optimization */
|
/* end of klibc optimization */
|
||||||
#define RT_USING_DEBUG
|
#define RT_USING_DEBUG
|
||||||
#define RT_DEBUGING_ASSERT
|
#define RT_DEBUGING_ASSERT
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
|
|
||||||
/* klibc optimization */
|
/* klibc optimization */
|
||||||
|
|
||||||
#define RT_KLIBC_USING_PRINTF_LONGLONG
|
#define RT_KLIBC_USING_VSNPRINTF_LONGLONG
|
||||||
/* end of klibc optimization */
|
/* end of klibc optimization */
|
||||||
#define RT_USING_DEBUG
|
#define RT_USING_DEBUG
|
||||||
#define RT_DEBUGING_ASSERT
|
#define RT_DEBUGING_ASSERT
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
|
|
||||||
/* klibc optimization */
|
/* klibc optimization */
|
||||||
|
|
||||||
#define RT_KLIBC_USING_PRINTF_LONGLONG
|
#define RT_KLIBC_USING_VSNPRINTF_LONGLONG
|
||||||
/* end of klibc optimization */
|
/* end of klibc optimization */
|
||||||
#define RT_USING_DEBUG
|
#define RT_USING_DEBUG
|
||||||
#define RT_DEBUGING_ASSERT
|
#define RT_DEBUGING_ASSERT
|
||||||
|
|
|
@ -27,7 +27,7 @@
|
||||||
|
|
||||||
/* klibc optimization */
|
/* klibc optimization */
|
||||||
|
|
||||||
#define RT_KLIBC_USING_PRINTF_LONGLONG
|
#define RT_KLIBC_USING_VSNPRINTF_LONGLONG
|
||||||
/* end of klibc optimization */
|
/* end of klibc optimization */
|
||||||
#define RT_USING_DEBUG
|
#define RT_USING_DEBUG
|
||||||
#define RT_DEBUGING_ASSERT
|
#define RT_DEBUGING_ASSERT
|
||||||
|
|
|
@ -821,33 +821,6 @@ CONFIG_PKG_AT_DEVICE_VER_NUM=0x99999
|
||||||
# system packages
|
# system packages
|
||||||
#
|
#
|
||||||
|
|
||||||
#
|
|
||||||
# enhanced kernel services
|
|
||||||
#
|
|
||||||
# CONFIG_PKG_USING_RT_MEMCPY_CM is not set
|
|
||||||
# CONFIG_PKG_USING_RT_KPRINTF_THREADSAFE is not set
|
|
||||||
CONFIG_PKG_USING_RT_VSNPRINTF_FULL=y
|
|
||||||
CONFIG_PKG_RT_VSNPRINTF_FULL_PATH="/packages/system/enhanced-kservice/rt_vsnprintf_full"
|
|
||||||
CONFIG_PKG_VSNPRINTF_SUPPORT_DECIMAL_SPECIFIERS=y
|
|
||||||
CONFIG_PKG_VSNPRINTF_SUPPORT_EXPONENTIAL_SPECIFIERS=y
|
|
||||||
CONFIG_PKG_VSNPRINTF_SUPPORT_WRITEBACK_SPECIFIER=y
|
|
||||||
CONFIG_PKG_VSNPRINTF_SUPPORT_LONG_LONG=y
|
|
||||||
CONFIG_PKG_VSNPRINTF_CHECK_FOR_NUL_IN_FORMAT_SPECIFIER=y
|
|
||||||
# CONFIG_PKG_VSNPRINTF_SUPPORT_MSVC_STYLE_INTEGER_SPECIFIERS is not set
|
|
||||||
CONFIG_PKG_VSNPRINTF_INTEGER_BUFFER_SIZE=32
|
|
||||||
CONFIG_PKG_VSNPRINTF_DECIMAL_BUFFER_SIZE=32
|
|
||||||
CONFIG_PKG_VSNPRINTF_DEFAULT_FLOAT_PRECISION=6
|
|
||||||
CONFIG_PKG_VSNPRINTF_MAX_INTEGRAL_DIGITS_FOR_DECIMAL=9
|
|
||||||
CONFIG_PKG_VSNPRINTF_LOG10_TAYLOR_TERMS=4
|
|
||||||
# CONFIG_RT_VSNPRINTF_FULL_REPLACING_SPRINTF is not set
|
|
||||||
# CONFIG_RT_VSNPRINTF_FULL_REPLACING_SNPRINTF is not set
|
|
||||||
# CONFIG_RT_VSNPRINTF_FULL_REPLACING_PRINTF is not set
|
|
||||||
# CONFIG_RT_VSNPRINTF_FULL_REPLACING_VSPRINTF is not set
|
|
||||||
# CONFIG_RT_VSNPRINTF_FULL_REPLACING_VSNPRINTF is not set
|
|
||||||
CONFIG_PKG_USING_RT_VSNPRINTF_FULL_LATEST_VERSION=y
|
|
||||||
CONFIG_PKG_RT_VSNPRINTF_FULL_VER="latest"
|
|
||||||
# end of enhanced kernel services
|
|
||||||
|
|
||||||
# CONFIG_PKG_USING_AUNITY is not set
|
# CONFIG_PKG_USING_AUNITY is not set
|
||||||
|
|
||||||
#
|
#
|
||||||
|
|
|
@ -801,33 +801,6 @@ CONFIG_PKG_AT_DEVICE_VER_NUM=0x99999
|
||||||
# system packages
|
# system packages
|
||||||
#
|
#
|
||||||
|
|
||||||
#
|
|
||||||
# enhanced kernel services
|
|
||||||
#
|
|
||||||
# CONFIG_PKG_USING_RT_MEMCPY_CM is not set
|
|
||||||
# CONFIG_PKG_USING_RT_KPRINTF_THREADSAFE is not set
|
|
||||||
CONFIG_PKG_USING_RT_VSNPRINTF_FULL=y
|
|
||||||
CONFIG_PKG_RT_VSNPRINTF_FULL_PATH="/packages/system/enhanced-kservice/rt_vsnprintf_full"
|
|
||||||
CONFIG_PKG_VSNPRINTF_SUPPORT_DECIMAL_SPECIFIERS=y
|
|
||||||
CONFIG_PKG_VSNPRINTF_SUPPORT_EXPONENTIAL_SPECIFIERS=y
|
|
||||||
CONFIG_PKG_VSNPRINTF_SUPPORT_WRITEBACK_SPECIFIER=y
|
|
||||||
CONFIG_PKG_VSNPRINTF_SUPPORT_LONG_LONG=y
|
|
||||||
CONFIG_PKG_VSNPRINTF_CHECK_FOR_NUL_IN_FORMAT_SPECIFIER=y
|
|
||||||
# CONFIG_PKG_VSNPRINTF_SUPPORT_MSVC_STYLE_INTEGER_SPECIFIERS is not set
|
|
||||||
CONFIG_PKG_VSNPRINTF_INTEGER_BUFFER_SIZE=32
|
|
||||||
CONFIG_PKG_VSNPRINTF_DECIMAL_BUFFER_SIZE=32
|
|
||||||
CONFIG_PKG_VSNPRINTF_DEFAULT_FLOAT_PRECISION=6
|
|
||||||
CONFIG_PKG_VSNPRINTF_MAX_INTEGRAL_DIGITS_FOR_DECIMAL=9
|
|
||||||
CONFIG_PKG_VSNPRINTF_LOG10_TAYLOR_TERMS=4
|
|
||||||
# CONFIG_RT_VSNPRINTF_FULL_REPLACING_SPRINTF is not set
|
|
||||||
# CONFIG_RT_VSNPRINTF_FULL_REPLACING_SNPRINTF is not set
|
|
||||||
# CONFIG_RT_VSNPRINTF_FULL_REPLACING_PRINTF is not set
|
|
||||||
# CONFIG_RT_VSNPRINTF_FULL_REPLACING_VSPRINTF is not set
|
|
||||||
# CONFIG_RT_VSNPRINTF_FULL_REPLACING_VSNPRINTF is not set
|
|
||||||
CONFIG_PKG_USING_RT_VSNPRINTF_FULL_LATEST_VERSION=y
|
|
||||||
CONFIG_PKG_RT_VSNPRINTF_FULL_VER="latest"
|
|
||||||
# end of enhanced kernel services
|
|
||||||
|
|
||||||
# CONFIG_PKG_USING_AUNITY is not set
|
# CONFIG_PKG_USING_AUNITY is not set
|
||||||
|
|
||||||
#
|
#
|
||||||
|
|
|
@ -735,33 +735,6 @@ CONFIG_PKG_AT_DEVICE_VER_NUM=0x99999
|
||||||
# system packages
|
# system packages
|
||||||
#
|
#
|
||||||
|
|
||||||
#
|
|
||||||
# enhanced kernel services
|
|
||||||
#
|
|
||||||
# CONFIG_PKG_USING_RT_MEMCPY_CM is not set
|
|
||||||
# CONFIG_PKG_USING_RT_KPRINTF_THREADSAFE is not set
|
|
||||||
CONFIG_PKG_USING_RT_VSNPRINTF_FULL=y
|
|
||||||
CONFIG_PKG_RT_VSNPRINTF_FULL_PATH="/packages/system/enhanced-kservice/rt_vsnprintf_full"
|
|
||||||
CONFIG_PKG_VSNPRINTF_SUPPORT_DECIMAL_SPECIFIERS=y
|
|
||||||
CONFIG_PKG_VSNPRINTF_SUPPORT_EXPONENTIAL_SPECIFIERS=y
|
|
||||||
CONFIG_PKG_VSNPRINTF_SUPPORT_WRITEBACK_SPECIFIER=y
|
|
||||||
CONFIG_PKG_VSNPRINTF_SUPPORT_LONG_LONG=y
|
|
||||||
CONFIG_PKG_VSNPRINTF_CHECK_FOR_NUL_IN_FORMAT_SPECIFIER=y
|
|
||||||
# CONFIG_PKG_VSNPRINTF_SUPPORT_MSVC_STYLE_INTEGER_SPECIFIERS is not set
|
|
||||||
CONFIG_PKG_VSNPRINTF_INTEGER_BUFFER_SIZE=32
|
|
||||||
CONFIG_PKG_VSNPRINTF_DECIMAL_BUFFER_SIZE=32
|
|
||||||
CONFIG_PKG_VSNPRINTF_DEFAULT_FLOAT_PRECISION=6
|
|
||||||
CONFIG_PKG_VSNPRINTF_MAX_INTEGRAL_DIGITS_FOR_DECIMAL=9
|
|
||||||
CONFIG_PKG_VSNPRINTF_LOG10_TAYLOR_TERMS=4
|
|
||||||
# CONFIG_RT_VSNPRINTF_FULL_REPLACING_SPRINTF is not set
|
|
||||||
# CONFIG_RT_VSNPRINTF_FULL_REPLACING_SNPRINTF is not set
|
|
||||||
# CONFIG_RT_VSNPRINTF_FULL_REPLACING_PRINTF is not set
|
|
||||||
# CONFIG_RT_VSNPRINTF_FULL_REPLACING_VSPRINTF is not set
|
|
||||||
# CONFIG_RT_VSNPRINTF_FULL_REPLACING_VSNPRINTF is not set
|
|
||||||
CONFIG_PKG_USING_RT_VSNPRINTF_FULL_LATEST_VERSION=y
|
|
||||||
CONFIG_PKG_RT_VSNPRINTF_FULL_VER="latest"
|
|
||||||
# end of enhanced kernel services
|
|
||||||
|
|
||||||
# CONFIG_PKG_USING_AUNITY is not set
|
# CONFIG_PKG_USING_AUNITY is not set
|
||||||
|
|
||||||
#
|
#
|
||||||
|
|
|
@ -773,33 +773,6 @@ CONFIG_RT_USB_MSTORAGE_DISK_NAME="ramdisk1"
|
||||||
# system packages
|
# system packages
|
||||||
#
|
#
|
||||||
|
|
||||||
#
|
|
||||||
# enhanced kernel services
|
|
||||||
#
|
|
||||||
# CONFIG_PKG_USING_RT_MEMCPY_CM is not set
|
|
||||||
# CONFIG_PKG_USING_RT_KPRINTF_THREADSAFE is not set
|
|
||||||
CONFIG_PKG_USING_RT_VSNPRINTF_FULL=y
|
|
||||||
CONFIG_PKG_RT_VSNPRINTF_FULL_PATH="/packages/system/enhanced-kservice/rt_vsnprintf_full"
|
|
||||||
CONFIG_PKG_VSNPRINTF_SUPPORT_DECIMAL_SPECIFIERS=y
|
|
||||||
CONFIG_PKG_VSNPRINTF_SUPPORT_EXPONENTIAL_SPECIFIERS=y
|
|
||||||
CONFIG_PKG_VSNPRINTF_SUPPORT_WRITEBACK_SPECIFIER=y
|
|
||||||
CONFIG_PKG_VSNPRINTF_SUPPORT_LONG_LONG=y
|
|
||||||
CONFIG_PKG_VSNPRINTF_CHECK_FOR_NUL_IN_FORMAT_SPECIFIER=y
|
|
||||||
# CONFIG_PKG_VSNPRINTF_SUPPORT_MSVC_STYLE_INTEGER_SPECIFIERS is not set
|
|
||||||
CONFIG_PKG_VSNPRINTF_INTEGER_BUFFER_SIZE=32
|
|
||||||
CONFIG_PKG_VSNPRINTF_DECIMAL_BUFFER_SIZE=32
|
|
||||||
CONFIG_PKG_VSNPRINTF_DEFAULT_FLOAT_PRECISION=6
|
|
||||||
CONFIG_PKG_VSNPRINTF_MAX_INTEGRAL_DIGITS_FOR_DECIMAL=9
|
|
||||||
CONFIG_PKG_VSNPRINTF_LOG10_TAYLOR_TERMS=4
|
|
||||||
# CONFIG_RT_VSNPRINTF_FULL_REPLACING_SPRINTF is not set
|
|
||||||
# CONFIG_RT_VSNPRINTF_FULL_REPLACING_SNPRINTF is not set
|
|
||||||
# CONFIG_RT_VSNPRINTF_FULL_REPLACING_PRINTF is not set
|
|
||||||
# CONFIG_RT_VSNPRINTF_FULL_REPLACING_VSPRINTF is not set
|
|
||||||
# CONFIG_RT_VSNPRINTF_FULL_REPLACING_VSNPRINTF is not set
|
|
||||||
CONFIG_PKG_USING_RT_VSNPRINTF_FULL_LATEST_VERSION=y
|
|
||||||
CONFIG_PKG_RT_VSNPRINTF_FULL_VER="latest"
|
|
||||||
# end of enhanced kernel services
|
|
||||||
|
|
||||||
# CONFIG_PKG_USING_AUNITY is not set
|
# CONFIG_PKG_USING_AUNITY is not set
|
||||||
|
|
||||||
#
|
#
|
||||||
|
|
|
@ -507,32 +507,6 @@ CONFIG_ULOG_BACKEND_USING_CONSOLE=y
|
||||||
# system packages
|
# system packages
|
||||||
#
|
#
|
||||||
|
|
||||||
#
|
|
||||||
# enhanced kernel services
|
|
||||||
#
|
|
||||||
# CONFIG_PKG_USING_RT_MEMCPY_CM is not set
|
|
||||||
# CONFIG_PKG_USING_RT_KPRINTF_THREADSAFE is not set
|
|
||||||
CONFIG_PKG_USING_RT_VSNPRINTF_FULL=y
|
|
||||||
CONFIG_PKG_RT_VSNPRINTF_FULL_PATH="/packages/system/enhanced-kservice/rt_vsnprintf_full"
|
|
||||||
# CONFIG_PKG_VSNPRINTF_SUPPORT_DECIMAL_SPECIFIERS is not set
|
|
||||||
# CONFIG_PKG_VSNPRINTF_SUPPORT_EXPONENTIAL_SPECIFIERS is not set
|
|
||||||
# CONFIG_PKG_VSNPRINTF_SUPPORT_WRITEBACK_SPECIFIER is not set
|
|
||||||
# CONFIG_PKG_VSNPRINTF_SUPPORT_LONG_LONG is not set
|
|
||||||
# CONFIG_PKG_VSNPRINTF_CHECK_FOR_NUL_IN_FORMAT_SPECIFIER is not set
|
|
||||||
# CONFIG_PKG_VSNPRINTF_SUPPORT_MSVC_STYLE_INTEGER_SPECIFIERS is not set
|
|
||||||
CONFIG_PKG_VSNPRINTF_INTEGER_BUFFER_SIZE=32
|
|
||||||
CONFIG_PKG_VSNPRINTF_DECIMAL_BUFFER_SIZE=32
|
|
||||||
CONFIG_PKG_VSNPRINTF_DEFAULT_FLOAT_PRECISION=6
|
|
||||||
CONFIG_PKG_VSNPRINTF_MAX_INTEGRAL_DIGITS_FOR_DECIMAL=9
|
|
||||||
CONFIG_PKG_VSNPRINTF_LOG10_TAYLOR_TERMS=4
|
|
||||||
# CONFIG_RT_VSNPRINTF_FULL_REPLACING_SPRINTF is not set
|
|
||||||
# CONFIG_RT_VSNPRINTF_FULL_REPLACING_SNPRINTF is not set
|
|
||||||
# CONFIG_RT_VSNPRINTF_FULL_REPLACING_PRINTF is not set
|
|
||||||
# CONFIG_RT_VSNPRINTF_FULL_REPLACING_VSPRINTF is not set
|
|
||||||
# CONFIG_RT_VSNPRINTF_FULL_REPLACING_VSNPRINTF is not set
|
|
||||||
CONFIG_PKG_USING_RT_VSNPRINTF_FULL_LATEST_VERSION=y
|
|
||||||
CONFIG_PKG_RT_VSNPRINTF_FULL_VER="latest"
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# acceleration: Assembly language or algorithmic acceleration packages
|
# acceleration: Assembly language or algorithmic acceleration packages
|
||||||
#
|
#
|
||||||
|
|
|
@ -558,33 +558,6 @@ CONFIG_ULOG_BACKEND_USING_CONSOLE=y
|
||||||
# system packages
|
# system packages
|
||||||
#
|
#
|
||||||
|
|
||||||
#
|
|
||||||
# enhanced kernel services
|
|
||||||
#
|
|
||||||
# CONFIG_PKG_USING_RT_MEMCPY_CM is not set
|
|
||||||
# CONFIG_PKG_USING_RT_KPRINTF_THREADSAFE is not set
|
|
||||||
CONFIG_PKG_USING_RT_VSNPRINTF_FULL=y
|
|
||||||
CONFIG_PKG_RT_VSNPRINTF_FULL_PATH="/packages/system/enhanced-kservice/rt_vsnprintf_full"
|
|
||||||
# CONFIG_PKG_VSNPRINTF_SUPPORT_DECIMAL_SPECIFIERS is not set
|
|
||||||
# CONFIG_PKG_VSNPRINTF_SUPPORT_EXPONENTIAL_SPECIFIERS is not set
|
|
||||||
# CONFIG_PKG_VSNPRINTF_SUPPORT_WRITEBACK_SPECIFIER is not set
|
|
||||||
# CONFIG_PKG_VSNPRINTF_SUPPORT_LONG_LONG is not set
|
|
||||||
# CONFIG_PKG_VSNPRINTF_CHECK_FOR_NUL_IN_FORMAT_SPECIFIER is not set
|
|
||||||
# CONFIG_PKG_VSNPRINTF_SUPPORT_MSVC_STYLE_INTEGER_SPECIFIERS is not set
|
|
||||||
CONFIG_PKG_VSNPRINTF_INTEGER_BUFFER_SIZE=32
|
|
||||||
CONFIG_PKG_VSNPRINTF_DECIMAL_BUFFER_SIZE=32
|
|
||||||
CONFIG_PKG_VSNPRINTF_DEFAULT_FLOAT_PRECISION=6
|
|
||||||
CONFIG_PKG_VSNPRINTF_MAX_INTEGRAL_DIGITS_FOR_DECIMAL=9
|
|
||||||
CONFIG_PKG_VSNPRINTF_LOG10_TAYLOR_TERMS=4
|
|
||||||
# CONFIG_RT_VSNPRINTF_FULL_REPLACING_SPRINTF is not set
|
|
||||||
# CONFIG_RT_VSNPRINTF_FULL_REPLACING_SNPRINTF is not set
|
|
||||||
# CONFIG_RT_VSNPRINTF_FULL_REPLACING_PRINTF is not set
|
|
||||||
# CONFIG_RT_VSNPRINTF_FULL_REPLACING_VSPRINTF is not set
|
|
||||||
# CONFIG_RT_VSNPRINTF_FULL_REPLACING_VSNPRINTF is not set
|
|
||||||
CONFIG_PKG_USING_RT_VSNPRINTF_FULL_LATEST_VERSION=y
|
|
||||||
CONFIG_PKG_RT_VSNPRINTF_FULL_VER="latest"
|
|
||||||
# end of enhanced kernel services
|
|
||||||
|
|
||||||
# CONFIG_PKG_USING_AUNITY is not set
|
# CONFIG_PKG_USING_AUNITY is not set
|
||||||
|
|
||||||
#
|
#
|
||||||
|
|
|
@ -512,26 +512,6 @@ CONFIG_ULOG_BACKEND_USING_CONSOLE=y
|
||||||
#
|
#
|
||||||
# CONFIG_PKG_USING_RT_MEMCPY_CM is not set
|
# CONFIG_PKG_USING_RT_MEMCPY_CM is not set
|
||||||
# CONFIG_PKG_USING_RT_KPRINTF_THREADSAFE is not set
|
# CONFIG_PKG_USING_RT_KPRINTF_THREADSAFE is not set
|
||||||
CONFIG_PKG_USING_RT_VSNPRINTF_FULL=y
|
|
||||||
CONFIG_PKG_RT_VSNPRINTF_FULL_PATH="/packages/system/enhanced-kservice/rt_vsnprintf_full"
|
|
||||||
# CONFIG_PKG_VSNPRINTF_SUPPORT_DECIMAL_SPECIFIERS is not set
|
|
||||||
# CONFIG_PKG_VSNPRINTF_SUPPORT_EXPONENTIAL_SPECIFIERS is not set
|
|
||||||
# CONFIG_PKG_VSNPRINTF_SUPPORT_WRITEBACK_SPECIFIER is not set
|
|
||||||
# CONFIG_PKG_VSNPRINTF_SUPPORT_LONG_LONG is not set
|
|
||||||
# CONFIG_PKG_VSNPRINTF_CHECK_FOR_NUL_IN_FORMAT_SPECIFIER is not set
|
|
||||||
# CONFIG_PKG_VSNPRINTF_SUPPORT_MSVC_STYLE_INTEGER_SPECIFIERS is not set
|
|
||||||
CONFIG_PKG_VSNPRINTF_INTEGER_BUFFER_SIZE=32
|
|
||||||
CONFIG_PKG_VSNPRINTF_DECIMAL_BUFFER_SIZE=32
|
|
||||||
CONFIG_PKG_VSNPRINTF_DEFAULT_FLOAT_PRECISION=6
|
|
||||||
CONFIG_PKG_VSNPRINTF_MAX_INTEGRAL_DIGITS_FOR_DECIMAL=9
|
|
||||||
CONFIG_PKG_VSNPRINTF_LOG10_TAYLOR_TERMS=4
|
|
||||||
# CONFIG_RT_VSNPRINTF_FULL_REPLACING_SPRINTF is not set
|
|
||||||
# CONFIG_RT_VSNPRINTF_FULL_REPLACING_SNPRINTF is not set
|
|
||||||
# CONFIG_RT_VSNPRINTF_FULL_REPLACING_PRINTF is not set
|
|
||||||
# CONFIG_RT_VSNPRINTF_FULL_REPLACING_VSPRINTF is not set
|
|
||||||
# CONFIG_RT_VSNPRINTF_FULL_REPLACING_VSNPRINTF is not set
|
|
||||||
CONFIG_PKG_USING_RT_VSNPRINTF_FULL_LATEST_VERSION=y
|
|
||||||
CONFIG_PKG_RT_VSNPRINTF_FULL_VER="latest"
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# acceleration: Assembly language or algorithmic acceleration packages
|
# acceleration: Assembly language or algorithmic acceleration packages
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
|
|
||||||
/* klibc optimization */
|
/* klibc optimization */
|
||||||
|
|
||||||
#define RT_KLIBC_USING_PRINTF_LONGLONG
|
#define RT_KLIBC_USING_VSNPRINTF_LONGLONG
|
||||||
/* end of klibc optimization */
|
/* end of klibc optimization */
|
||||||
#define RT_USING_DEBUG
|
#define RT_USING_DEBUG
|
||||||
#define RT_DEBUGING_ASSERT
|
#define RT_DEBUGING_ASSERT
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
|
|
||||||
/* klibc optimization */
|
/* klibc optimization */
|
||||||
|
|
||||||
#define RT_KLIBC_USING_PRINTF_LONGLONG
|
#define RT_KLIBC_USING_VSNPRINTF_LONGLONG
|
||||||
/* end of klibc optimization */
|
/* end of klibc optimization */
|
||||||
#define RT_USING_DEBUG
|
#define RT_USING_DEBUG
|
||||||
#define RT_DEBUGING_ASSERT
|
#define RT_DEBUGING_ASSERT
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
|
|
||||||
/* klibc optimization */
|
/* klibc optimization */
|
||||||
|
|
||||||
#define RT_KLIBC_USING_PRINTF_LONGLONG
|
#define RT_KLIBC_USING_VSNPRINTF_LONGLONG
|
||||||
/* end of klibc optimization */
|
/* end of klibc optimization */
|
||||||
#define RT_USING_DEBUG
|
#define RT_USING_DEBUG
|
||||||
#define RT_DEBUGING_ASSERT
|
#define RT_DEBUGING_ASSERT
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
|
|
||||||
/* klibc optimization */
|
/* klibc optimization */
|
||||||
|
|
||||||
#define RT_KLIBC_USING_PRINTF_LONGLONG
|
#define RT_KLIBC_USING_VSNPRINTF_LONGLONG
|
||||||
/* end of klibc optimization */
|
/* end of klibc optimization */
|
||||||
#define RT_USING_DEBUG
|
#define RT_USING_DEBUG
|
||||||
#define RT_DEBUGING_ASSERT
|
#define RT_DEBUGING_ASSERT
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
|
|
||||||
/* klibc optimization */
|
/* klibc optimization */
|
||||||
|
|
||||||
#define RT_KLIBC_USING_PRINTF_LONGLONG
|
#define RT_KLIBC_USING_VSNPRINTF_LONGLONG
|
||||||
/* end of klibc optimization */
|
/* end of klibc optimization */
|
||||||
#define RT_USING_DEBUG
|
#define RT_USING_DEBUG
|
||||||
#define RT_DEBUGING_ASSERT
|
#define RT_DEBUGING_ASSERT
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
|
|
||||||
/* klibc optimization */
|
/* klibc optimization */
|
||||||
|
|
||||||
#define RT_KLIBC_USING_PRINTF_LONGLONG
|
#define RT_KLIBC_USING_VSNPRINTF_LONGLONG
|
||||||
/* end of klibc optimization */
|
/* end of klibc optimization */
|
||||||
#define RT_USING_DEBUG
|
#define RT_USING_DEBUG
|
||||||
#define RT_DEBUGING_ASSERT
|
#define RT_DEBUGING_ASSERT
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
|
|
||||||
/* klibc optimization */
|
/* klibc optimization */
|
||||||
|
|
||||||
#define RT_KLIBC_USING_PRINTF_LONGLONG
|
#define RT_KLIBC_USING_VSNPRINTF_LONGLONG
|
||||||
/* end of klibc optimization */
|
/* end of klibc optimization */
|
||||||
#define RT_USING_DEBUG
|
#define RT_USING_DEBUG
|
||||||
#define RT_DEBUGING_ASSERT
|
#define RT_DEBUGING_ASSERT
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
|
|
||||||
/* klibc optimization */
|
/* klibc optimization */
|
||||||
|
|
||||||
#define RT_KLIBC_USING_PRINTF_LONGLONG
|
#define RT_KLIBC_USING_VSNPRINTF_LONGLONG
|
||||||
/* end of klibc optimization */
|
/* end of klibc optimization */
|
||||||
#define RT_USING_DEBUG
|
#define RT_USING_DEBUG
|
||||||
#define RT_DEBUGING_ASSERT
|
#define RT_DEBUGING_ASSERT
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
|
|
||||||
/* klibc optimization */
|
/* klibc optimization */
|
||||||
|
|
||||||
#define RT_KLIBC_USING_PRINTF_LONGLONG
|
#define RT_KLIBC_USING_VSNPRINTF_LONGLONG
|
||||||
/* end of klibc optimization */
|
/* end of klibc optimization */
|
||||||
#define RT_USING_DEBUG
|
#define RT_USING_DEBUG
|
||||||
#define RT_DEBUGING_ASSERT
|
#define RT_DEBUGING_ASSERT
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
|
|
||||||
/* klibc optimization */
|
/* klibc optimization */
|
||||||
|
|
||||||
#define RT_KLIBC_USING_PRINTF_LONGLONG
|
#define RT_KLIBC_USING_VSNPRINTF_LONGLONG
|
||||||
/* end of klibc optimization */
|
/* end of klibc optimization */
|
||||||
#define RT_USING_DEBUG
|
#define RT_USING_DEBUG
|
||||||
#define RT_DEBUGING_ASSERT
|
#define RT_DEBUGING_ASSERT
|
||||||
|
|
|
@ -25,7 +25,7 @@
|
||||||
|
|
||||||
/* klibc optimization */
|
/* klibc optimization */
|
||||||
|
|
||||||
#define RT_KLIBC_USING_PRINTF_LONGLONG
|
#define RT_KLIBC_USING_VSNPRINTF_LONGLONG
|
||||||
/* end of klibc optimization */
|
/* end of klibc optimization */
|
||||||
#define RT_USING_DEBUG
|
#define RT_USING_DEBUG
|
||||||
#define RT_DEBUGING_ASSERT
|
#define RT_DEBUGING_ASSERT
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
|
|
||||||
/* klibc optimization */
|
/* klibc optimization */
|
||||||
|
|
||||||
#define RT_KLIBC_USING_PRINTF_LONGLONG
|
#define RT_KLIBC_USING_VSNPRINTF_LONGLONG
|
||||||
/* end of klibc optimization */
|
/* end of klibc optimization */
|
||||||
#define RT_USING_DEBUG
|
#define RT_USING_DEBUG
|
||||||
#define RT_DEBUGING_COLOR
|
#define RT_DEBUGING_COLOR
|
||||||
|
|
|
@ -30,7 +30,7 @@
|
||||||
|
|
||||||
/* klibc optimization */
|
/* klibc optimization */
|
||||||
|
|
||||||
#define RT_KLIBC_USING_PRINTF_LONGLONG
|
#define RT_KLIBC_USING_VSNPRINTF_LONGLONG
|
||||||
/* end of klibc optimization */
|
/* end of klibc optimization */
|
||||||
#define RT_USING_DEBUG
|
#define RT_USING_DEBUG
|
||||||
#define RT_DEBUGING_COLOR
|
#define RT_DEBUGING_COLOR
|
||||||
|
|
|
@ -1,3 +0,0 @@
|
||||||
# scons: --strict
|
|
||||||
|
|
||||||
CONFIG_RT_KLIBC_USING_PRINTF_LONGLONG=y
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
# scons: --strict
|
||||||
|
|
||||||
|
CONFIG_RT_KLIBC_USING_VSNPRINTF_STANDARD=y
|
||||||
|
CONFIG_RT_KLIBC_USING_PRINTF_LONGLONG=y
|
||||||
|
CONFIG_RT_KLIBC_USING_VSNPRINTF_DECIMAL_SPECIFIERS=y
|
||||||
|
CONFIG_RT_KLIBC_USING_VSNPRINTF_EXPONENTIAL_SPECIFIERS=y
|
||||||
|
CONFIG_RT_KLIBC_USING_VSNPRINTF_WRITEBACK_SPECIFIER=y
|
||||||
|
CONFIG_RT_KLIBC_USING_VSNPRINTF_CHECK_NUL_IN_FORMAT_SPECIFIER=y
|
||||||
|
CONFIG_RT_KLIBC_USING_VSNPRINTF_MSVC_STYLE_INTEGER_SPECIFIERS=y
|
|
@ -1,4 +1,3 @@
|
||||||
# scons: --strict
|
# scons: --strict
|
||||||
CONFIG_PKG_USING_RT_KPRINTF_THREADSAFE=y
|
CONFIG_PKG_USING_RT_KPRINTF_THREADSAFE=y
|
||||||
CONFIG_PKG_USING_RT_MEMCPY_CM=y
|
CONFIG_PKG_USING_RT_MEMCPY_CM=y
|
||||||
CONFIG_PKG_USING_RT_VSNPRINTF_FULL=y
|
|
||||||
|
|
|
@ -10,6 +10,6 @@ if RT_USING_SENSOR
|
||||||
|
|
||||||
config RT_USING_SENSOR_CMD
|
config RT_USING_SENSOR_CMD
|
||||||
bool "Using Sensor cmd"
|
bool "Using Sensor cmd"
|
||||||
select PKG_USING_RT_VSNPRINTF_FULL if RT_USING_SENSOR_V2
|
select RT_KLIBC_USING_VSNPRINTF_STANDARD if RT_USING_SENSOR_V2
|
||||||
default y
|
default y
|
||||||
endif
|
endif
|
||||||
|
|
|
@ -137,7 +137,7 @@ menuconfig RT_USING_ULOG
|
||||||
config ULOG_OUTPUT_FLOAT
|
config ULOG_OUTPUT_FLOAT
|
||||||
bool "Enable float number support. It will using more thread stack."
|
bool "Enable float number support. It will using more thread stack."
|
||||||
default n
|
default n
|
||||||
select PKG_USING_RT_VSNPRINTF_FULL
|
select RT_KLIBC_USING_VSNPRINTF_STANDARD
|
||||||
help
|
help
|
||||||
The default formater is using rt_vsnprint and it not supported float number.
|
The default formater is using rt_vsnprint and it not supported float number.
|
||||||
When enable this option then it will enable libc. The formater will change to vsnprint on libc.
|
When enable this option then it will enable libc. The formater will change to vsnprint on libc.
|
||||||
|
|
103
src/Kconfig
103
src/Kconfig
|
@ -189,13 +189,13 @@ config RT_USING_CPU_USAGE_TRACER
|
||||||
default y if RT_USING_SMART
|
default y if RT_USING_SMART
|
||||||
default n
|
default n
|
||||||
|
|
||||||
menu "kservice optimization"
|
menu "kservice options"
|
||||||
config RT_USING_TINY_FFS
|
config RT_USING_TINY_FFS
|
||||||
bool "Enable kservice to use tiny finding first bit set method"
|
bool "Enable kservice to use tiny finding first bit set method"
|
||||||
default n
|
default n
|
||||||
endmenu
|
endmenu
|
||||||
|
|
||||||
menu "klibc optimization"
|
menu "klibc options"
|
||||||
|
|
||||||
config RT_KLIBC_USING_STDLIB
|
config RT_KLIBC_USING_STDLIB
|
||||||
bool "Enable klibc to use standard C library"
|
bool "Enable klibc to use standard C library"
|
||||||
|
@ -213,15 +213,104 @@ menu "klibc optimization"
|
||||||
bool "Enable tiny size of klibc"
|
bool "Enable tiny size of klibc"
|
||||||
default n
|
default n
|
||||||
|
|
||||||
config RT_KLIBC_USING_PRINTF_LONGLONG
|
menu "rt_vsnprintf options"
|
||||||
bool "Enable rt_printf-family functions to support long-long format"
|
config RT_KLIBC_USING_VSNPRINTF_STANDARD
|
||||||
|
bool "standard rt_vsnprintf version"
|
||||||
default y if ARCH_CPU_64BIT
|
default y if ARCH_CPU_64BIT
|
||||||
default n
|
default n
|
||||||
help
|
help
|
||||||
Enable rt_printf()/rt_snprintf()/rt_sprintf()/rt_vsnprintf()/rt_vsprintf()
|
Standard version of rt_vsnprintf, which is full function but higher stack usage.
|
||||||
functions to support long-long format
|
|
||||||
|
|
||||||
endmenu
|
config RT_KLIBC_USING_VSNPRINTF_LONGLONG
|
||||||
|
bool "Enable rt_vsnprintf function to support long-long format"
|
||||||
|
default y if RT_KLIBC_USING_VSNPRINTF_STANDARD
|
||||||
|
default n
|
||||||
|
help
|
||||||
|
Support for the long long integral types (with the ll, z and t length modifiers for specifiers
|
||||||
|
%d,%i,%o,%x,%X,%u, and with the %p specifier). Note: 'L' (long double) is not supported.
|
||||||
|
|
||||||
|
if RT_KLIBC_USING_VSNPRINTF_STANDARD
|
||||||
|
|
||||||
|
config RT_KLIBC_USING_VSNPRINTF_DECIMAL_SPECIFIERS
|
||||||
|
bool "Support decimal notation floating point conversion specifiers (%f, %F)"
|
||||||
|
default y
|
||||||
|
help
|
||||||
|
Support for the decimal notation floating point conversion specifiers (%f, %F)
|
||||||
|
|
||||||
|
config RT_KLIBC_USING_VSNPRINTF_EXPONENTIAL_SPECIFIERS
|
||||||
|
bool "Support exponential notation floating point conversion specifiers (%e, %g, %E, %G)"
|
||||||
|
default y
|
||||||
|
help
|
||||||
|
Support for the exponential notation floating point conversion specifiers (%e, %g, %E, %G)
|
||||||
|
|
||||||
|
config RT_KLIBC_USING_VSNPRINTF_WRITEBACK_SPECIFIER
|
||||||
|
bool "Support length write-back specifier (%n)"
|
||||||
|
default y
|
||||||
|
help
|
||||||
|
Support for the length write-back specifier (%n)
|
||||||
|
|
||||||
|
config RT_KLIBC_USING_VSNPRINTF_CHECK_NUL_IN_FORMAT_SPECIFIER
|
||||||
|
bool "safety check: no NULL end string"
|
||||||
|
default y if RT_USING_DEBUG
|
||||||
|
default n
|
||||||
|
help
|
||||||
|
Be extra-safe, and don't assume format specifiers are completed correctly
|
||||||
|
before the format string end.
|
||||||
|
|
||||||
|
config RT_KLIBC_USING_VSNPRINTF_MSVC_STYLE_INTEGER_SPECIFIERS
|
||||||
|
bool "Support MSVC style integer specifiers"
|
||||||
|
default n
|
||||||
|
help
|
||||||
|
the integer format specifiers used in Microsoft's Visual C++ (MSVC) compiler.
|
||||||
|
These specifiers, like %I64d for 64-bit integers, deviate slightly from the standard
|
||||||
|
C format specifiers and are specific to MSVC. They allow for controlled formatting of
|
||||||
|
integers in printf()-like functions, accommodating different integer sizes and ensuring
|
||||||
|
compatibility with MSVC's environment. It's important to note that these specifiers might
|
||||||
|
not be recognized or function in other compilers due to their MSVC-specific nature.
|
||||||
|
|
||||||
|
config RT_KLIBC_USING_VSNPRINTF_INTEGER_BUFFER_SIZE
|
||||||
|
int "'ntoa' conversion buffer size"
|
||||||
|
default 32
|
||||||
|
help
|
||||||
|
'ntoa' conversion buffer size, this must be big enough to hold one converted
|
||||||
|
numeric number including padded zeros (dynamically created on stack)
|
||||||
|
|
||||||
|
config RT_KLIBC_USING_VSNPRINTF_DECIMAL_BUFFER_SIZE
|
||||||
|
int "printing individual decimal numbers buffer size"
|
||||||
|
default 32
|
||||||
|
help
|
||||||
|
size of the fixed (on-stack) buffer for printing individual decimal numbers.
|
||||||
|
this must be big enough to hold one converted floating-point value including
|
||||||
|
padded zeros.
|
||||||
|
|
||||||
|
config RT_KLIBC_USING_VSNPRINTF_FLOAT_PRECISION
|
||||||
|
int "floating point conversion specifiers"
|
||||||
|
default 6
|
||||||
|
help
|
||||||
|
Default precision for the floating point conversion specifiers (the C standard sets this at 6)
|
||||||
|
|
||||||
|
config RT_KLIBC_USING_VSNPRINTF_MAX_INTEGRAL_DIGITS_FOR_DECIMAL
|
||||||
|
int "integral nums printed as float in rt_vsnprint"
|
||||||
|
default 9
|
||||||
|
help
|
||||||
|
According to the C languages standard, printf() and related functions must be able to print any
|
||||||
|
integral number in floating-point notation, regardless of length, when using the %f specifier -
|
||||||
|
possibly hundreds of characters, potentially overflowing your buffers. In this implementation,
|
||||||
|
all values beyond this threshold are switched to exponential notation.
|
||||||
|
|
||||||
|
config RT_KLIBC_USING_VSNPRINTF_LOG10_TAYLOR_TERMS
|
||||||
|
int "the number of terms in a Taylor series expansion of log_10(x)"
|
||||||
|
default 4
|
||||||
|
range 2 99
|
||||||
|
help
|
||||||
|
The number of terms in a Taylor series expansion of log_10(x) to
|
||||||
|
use for approximation - including the power-zero term (i.e. the
|
||||||
|
value at the point of expansion).
|
||||||
|
|
||||||
|
endif
|
||||||
|
endmenu # rt_vsnprintf options
|
||||||
|
|
||||||
|
endmenu # klibc options
|
||||||
|
|
||||||
menuconfig RT_USING_DEBUG
|
menuconfig RT_USING_DEBUG
|
||||||
bool "Enable debugging features"
|
bool "Enable debugging features"
|
||||||
|
|
|
@ -10,14 +10,6 @@
|
||||||
|
|
||||||
#include <rtthread.h>
|
#include <rtthread.h>
|
||||||
|
|
||||||
#define DBG_TAG "kernel.errno"
|
|
||||||
#ifdef RT_DEBUG_DEVICE
|
|
||||||
#define DBG_LVL DBG_LOG
|
|
||||||
#else
|
|
||||||
#define DBG_LVL DBG_WARNING
|
|
||||||
#endif /* defined (RT_DEBUG_DEVICE) */
|
|
||||||
#include <rtdbg.h>
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief A global variable used to store the error code.
|
* @brief A global variable used to store the error code.
|
||||||
*
|
*
|
||||||
|
|
|
@ -10,615 +10,6 @@
|
||||||
|
|
||||||
#include <rtthread.h>
|
#include <rtthread.h>
|
||||||
|
|
||||||
#define DBG_TAG "kernel.stdio"
|
|
||||||
#ifdef RT_DEBUG_DEVICE
|
|
||||||
#define DBG_LVL DBG_LOG
|
|
||||||
#else
|
|
||||||
#define DBG_LVL DBG_WARNING
|
|
||||||
#endif /* defined (RT_DEBUG_DEVICE) */
|
|
||||||
#include <rtdbg.h>
|
|
||||||
|
|
||||||
#define _ISDIGIT(c) ((unsigned)((c) - '0') < 10)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief This function will duplicate a string.
|
|
||||||
*
|
|
||||||
* @param n is the string to be duplicated.
|
|
||||||
*
|
|
||||||
* @param base is support divide instructions value.
|
|
||||||
*
|
|
||||||
* @return the duplicated string pointer.
|
|
||||||
*/
|
|
||||||
#ifdef RT_KLIBC_USING_PRINTF_LONGLONG
|
|
||||||
rt_inline int divide(unsigned long long *n, int base)
|
|
||||||
#else
|
|
||||||
rt_inline int divide(unsigned long *n, int base)
|
|
||||||
#endif /* RT_KLIBC_USING_PRINTF_LONGLONG */
|
|
||||||
{
|
|
||||||
int res;
|
|
||||||
|
|
||||||
/* optimized for processor which does not support divide instructions. */
|
|
||||||
#ifdef RT_KLIBC_USING_PRINTF_LONGLONG
|
|
||||||
res = (int)((*n) % base);
|
|
||||||
*n = (long long)((*n) / base);
|
|
||||||
#else
|
|
||||||
res = (int)((*n) % base);
|
|
||||||
*n = (long)((*n) / base);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
rt_inline int skip_atoi(const char **s)
|
|
||||||
{
|
|
||||||
int i = 0;
|
|
||||||
while (_ISDIGIT(**s))
|
|
||||||
i = i * 10 + *((*s)++) - '0';
|
|
||||||
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
|
|
||||||
#define ZEROPAD (1 << 0) /* pad with zero */
|
|
||||||
#define SIGN (1 << 1) /* unsigned/signed long */
|
|
||||||
#define PLUS (1 << 2) /* show plus */
|
|
||||||
#define SPACE (1 << 3) /* space if plus */
|
|
||||||
#define LEFT (1 << 4) /* left justified */
|
|
||||||
#define SPECIAL (1 << 5) /* 0x */
|
|
||||||
#define LARGE (1 << 6) /* use 'ABCDEF' instead of 'abcdef' */
|
|
||||||
|
|
||||||
static char *print_number(char *buf,
|
|
||||||
char *end,
|
|
||||||
#ifdef RT_KLIBC_USING_PRINTF_LONGLONG
|
|
||||||
unsigned long long num,
|
|
||||||
#else
|
|
||||||
unsigned long num,
|
|
||||||
#endif /* RT_KLIBC_USING_PRINTF_LONGLONG */
|
|
||||||
int base,
|
|
||||||
int qualifier,
|
|
||||||
int s,
|
|
||||||
int precision,
|
|
||||||
int type)
|
|
||||||
{
|
|
||||||
char c = 0, sign = 0;
|
|
||||||
#ifdef RT_KLIBC_USING_PRINTF_LONGLONG
|
|
||||||
char tmp[64] = {0};
|
|
||||||
#else
|
|
||||||
char tmp[32] = {0};
|
|
||||||
#endif /* RT_KLIBC_USING_PRINTF_LONGLONG */
|
|
||||||
int precision_bak = precision;
|
|
||||||
const char *digits = RT_NULL;
|
|
||||||
static const char small_digits[] = "0123456789abcdef";
|
|
||||||
static const char large_digits[] = "0123456789ABCDEF";
|
|
||||||
int i = 0;
|
|
||||||
int size = 0;
|
|
||||||
|
|
||||||
size = s;
|
|
||||||
|
|
||||||
digits = (type & LARGE) ? large_digits : small_digits;
|
|
||||||
if (type & LEFT)
|
|
||||||
{
|
|
||||||
type &= ~ZEROPAD;
|
|
||||||
}
|
|
||||||
|
|
||||||
c = (type & ZEROPAD) ? '0' : ' ';
|
|
||||||
|
|
||||||
/* get sign */
|
|
||||||
sign = 0;
|
|
||||||
if (type & SIGN)
|
|
||||||
{
|
|
||||||
switch (qualifier)
|
|
||||||
{
|
|
||||||
case 'h':
|
|
||||||
if ((rt_int16_t)num < 0)
|
|
||||||
{
|
|
||||||
sign = '-';
|
|
||||||
num = (rt_uint16_t)-num;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 'L':
|
|
||||||
case 'l':
|
|
||||||
if ((long)num < 0)
|
|
||||||
{
|
|
||||||
sign = '-';
|
|
||||||
num = (unsigned long)-num;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 0:
|
|
||||||
default:
|
|
||||||
if ((rt_int32_t)num < 0)
|
|
||||||
{
|
|
||||||
sign = '-';
|
|
||||||
num = (rt_uint32_t)-num;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (sign != '-')
|
|
||||||
{
|
|
||||||
if (type & PLUS)
|
|
||||||
{
|
|
||||||
sign = '+';
|
|
||||||
}
|
|
||||||
else if (type & SPACE)
|
|
||||||
{
|
|
||||||
sign = ' ';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (type & SPECIAL)
|
|
||||||
{
|
|
||||||
if (base == 2 || base == 16)
|
|
||||||
{
|
|
||||||
size -= 2;
|
|
||||||
}
|
|
||||||
else if (base == 8)
|
|
||||||
{
|
|
||||||
size--;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
if (num == 0)
|
|
||||||
{
|
|
||||||
tmp[i++] = '0';
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
while (num != 0)
|
|
||||||
tmp[i++] = digits[divide(&num, base)];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (i > precision)
|
|
||||||
{
|
|
||||||
precision = i;
|
|
||||||
}
|
|
||||||
size -= precision;
|
|
||||||
|
|
||||||
if (!(type & (ZEROPAD | LEFT)))
|
|
||||||
{
|
|
||||||
if ((sign) && (size > 0))
|
|
||||||
{
|
|
||||||
size--;
|
|
||||||
}
|
|
||||||
|
|
||||||
while (size-- > 0)
|
|
||||||
{
|
|
||||||
if (buf < end)
|
|
||||||
{
|
|
||||||
*buf = ' ';
|
|
||||||
}
|
|
||||||
|
|
||||||
++ buf;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (sign)
|
|
||||||
{
|
|
||||||
if (buf < end)
|
|
||||||
{
|
|
||||||
*buf = sign;
|
|
||||||
}
|
|
||||||
-- size;
|
|
||||||
++ buf;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (type & SPECIAL)
|
|
||||||
{
|
|
||||||
if (base == 2)
|
|
||||||
{
|
|
||||||
if (buf < end)
|
|
||||||
*buf = '0';
|
|
||||||
++ buf;
|
|
||||||
if (buf < end)
|
|
||||||
*buf = 'b';
|
|
||||||
++ buf;
|
|
||||||
}
|
|
||||||
else if (base == 8)
|
|
||||||
{
|
|
||||||
if (buf < end)
|
|
||||||
*buf = '0';
|
|
||||||
++ buf;
|
|
||||||
}
|
|
||||||
else if (base == 16)
|
|
||||||
{
|
|
||||||
if (buf < end)
|
|
||||||
{
|
|
||||||
*buf = '0';
|
|
||||||
}
|
|
||||||
|
|
||||||
++ buf;
|
|
||||||
if (buf < end)
|
|
||||||
{
|
|
||||||
*buf = type & LARGE ? 'X' : 'x';
|
|
||||||
}
|
|
||||||
++ buf;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* no align to the left */
|
|
||||||
if (!(type & LEFT))
|
|
||||||
{
|
|
||||||
while (size-- > 0)
|
|
||||||
{
|
|
||||||
if (buf < end)
|
|
||||||
{
|
|
||||||
*buf = c;
|
|
||||||
}
|
|
||||||
|
|
||||||
++ buf;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
while (i < precision--)
|
|
||||||
{
|
|
||||||
if (buf < end)
|
|
||||||
{
|
|
||||||
*buf = '0';
|
|
||||||
}
|
|
||||||
|
|
||||||
++ buf;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* put number in the temporary buffer */
|
|
||||||
while (i-- > 0 && (precision_bak != 0))
|
|
||||||
{
|
|
||||||
if (buf < end)
|
|
||||||
{
|
|
||||||
*buf = tmp[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
++ buf;
|
|
||||||
}
|
|
||||||
|
|
||||||
while (size-- > 0)
|
|
||||||
{
|
|
||||||
if (buf < end)
|
|
||||||
{
|
|
||||||
*buf = ' ';
|
|
||||||
}
|
|
||||||
|
|
||||||
++ buf;
|
|
||||||
}
|
|
||||||
|
|
||||||
return buf;
|
|
||||||
}
|
|
||||||
|
|
||||||
#if (defined(__GNUC__) && !defined(__ARMCC_VERSION) /* GCC */) && (__GNUC__ >= 7)
|
|
||||||
/* Disable "-Wimplicit-fallthrough" below GNUC V7 */
|
|
||||||
#pragma GCC diagnostic push
|
|
||||||
/* ignore warning: this statement may fall through */
|
|
||||||
#pragma GCC diagnostic ignored "-Wimplicit-fallthrough"
|
|
||||||
#endif /* (defined(__GNUC__) && !defined(__ARMCC_VERSION)) && (__GNUC__ >= 7 */
|
|
||||||
/**
|
|
||||||
* @brief This function will fill a formatted string to buffer.
|
|
||||||
*
|
|
||||||
* @param buf is the buffer to save formatted string.
|
|
||||||
*
|
|
||||||
* @param size is the size of buffer.
|
|
||||||
*
|
|
||||||
* @param fmt is the format parameters.
|
|
||||||
*
|
|
||||||
* @param args is a list of variable parameters.
|
|
||||||
*
|
|
||||||
* @return The number of characters actually written to buffer.
|
|
||||||
*/
|
|
||||||
rt_weak int rt_vsnprintf(char *buf, rt_size_t size, const char *fmt, va_list args)
|
|
||||||
{
|
|
||||||
#ifdef RT_KLIBC_USING_PRINTF_LONGLONG
|
|
||||||
unsigned long long num = 0;
|
|
||||||
#else
|
|
||||||
unsigned long num = 0;
|
|
||||||
#endif /* RT_KLIBC_USING_PRINTF_LONGLONG */
|
|
||||||
int i = 0, len = 0;
|
|
||||||
char *str = RT_NULL, *end = RT_NULL, c = 0;
|
|
||||||
const char *s = RT_NULL;
|
|
||||||
|
|
||||||
rt_uint8_t base = 0; /* the base of number */
|
|
||||||
rt_uint8_t flags = 0; /* flags to print number */
|
|
||||||
rt_uint8_t qualifier = 0; /* 'h', 'l', or 'L' for integer fields */
|
|
||||||
rt_int32_t field_width = 0; /* width of output field */
|
|
||||||
int precision = 0; /* min. # of digits for integers and max for a string */
|
|
||||||
|
|
||||||
str = buf;
|
|
||||||
end = buf + size;
|
|
||||||
|
|
||||||
/* Make sure end is always >= buf */
|
|
||||||
if (end < buf)
|
|
||||||
{
|
|
||||||
end = ((char *) - 1);
|
|
||||||
size = end - buf;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (; *fmt ; ++fmt)
|
|
||||||
{
|
|
||||||
if (*fmt != '%')
|
|
||||||
{
|
|
||||||
if (str < end)
|
|
||||||
{
|
|
||||||
*str = *fmt;
|
|
||||||
}
|
|
||||||
|
|
||||||
++ str;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* process flags */
|
|
||||||
flags = 0;
|
|
||||||
|
|
||||||
while (1)
|
|
||||||
{
|
|
||||||
/* skips the first '%' also */
|
|
||||||
++fmt;
|
|
||||||
if (*fmt == '-') flags |= LEFT;
|
|
||||||
else if (*fmt == '+') flags |= PLUS;
|
|
||||||
else if (*fmt == ' ') flags |= SPACE;
|
|
||||||
else if (*fmt == '#') flags |= SPECIAL;
|
|
||||||
else if (*fmt == '0') flags |= ZEROPAD;
|
|
||||||
else break;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* get field width */
|
|
||||||
field_width = -1;
|
|
||||||
if (_ISDIGIT(*fmt))
|
|
||||||
{
|
|
||||||
field_width = skip_atoi(&fmt);
|
|
||||||
}
|
|
||||||
else if (*fmt == '*')
|
|
||||||
{
|
|
||||||
++fmt;
|
|
||||||
/* it's the next argument */
|
|
||||||
field_width = va_arg(args, int);
|
|
||||||
if (field_width < 0)
|
|
||||||
{
|
|
||||||
field_width = -field_width;
|
|
||||||
flags |= LEFT;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* get the precision */
|
|
||||||
precision = -1;
|
|
||||||
if (*fmt == '.')
|
|
||||||
{
|
|
||||||
++fmt;
|
|
||||||
if (_ISDIGIT(*fmt))
|
|
||||||
{
|
|
||||||
precision = skip_atoi(&fmt);
|
|
||||||
}
|
|
||||||
else if (*fmt == '*')
|
|
||||||
{
|
|
||||||
++fmt;
|
|
||||||
/* it's the next argument */
|
|
||||||
precision = va_arg(args, int);
|
|
||||||
}
|
|
||||||
if (precision < 0)
|
|
||||||
{
|
|
||||||
precision = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
qualifier = 0; /* get the conversion qualifier */
|
|
||||||
|
|
||||||
if (*fmt == 'h' || *fmt == 'l' ||
|
|
||||||
#ifdef RT_KLIBC_USING_PRINTF_LONGLONG
|
|
||||||
*fmt == 'L' ||
|
|
||||||
#endif /* RT_KLIBC_USING_PRINTF_LONGLONG */
|
|
||||||
*fmt == 'z')
|
|
||||||
{
|
|
||||||
qualifier = *fmt;
|
|
||||||
++fmt;
|
|
||||||
#ifdef RT_KLIBC_USING_PRINTF_LONGLONG
|
|
||||||
if (qualifier == 'l' && *fmt == 'l')
|
|
||||||
{
|
|
||||||
qualifier = 'L';
|
|
||||||
++fmt;
|
|
||||||
}
|
|
||||||
#endif /* RT_KLIBC_USING_PRINTF_LONGLONG */
|
|
||||||
if (qualifier == 'h' && *fmt == 'h')
|
|
||||||
{
|
|
||||||
qualifier = 'H';
|
|
||||||
++fmt;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* the default base */
|
|
||||||
base = 10;
|
|
||||||
|
|
||||||
switch (*fmt)
|
|
||||||
{
|
|
||||||
case 'c':
|
|
||||||
if (!(flags & LEFT))
|
|
||||||
{
|
|
||||||
while (--field_width > 0)
|
|
||||||
{
|
|
||||||
if (str < end) *str = ' ';
|
|
||||||
++ str;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* get character */
|
|
||||||
c = (rt_uint8_t)va_arg(args, int);
|
|
||||||
if (str < end)
|
|
||||||
{
|
|
||||||
*str = c;
|
|
||||||
}
|
|
||||||
++ str;
|
|
||||||
|
|
||||||
/* put width */
|
|
||||||
while (--field_width > 0)
|
|
||||||
{
|
|
||||||
if (str < end) *str = ' ';
|
|
||||||
++ str;
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
|
|
||||||
case 's':
|
|
||||||
s = va_arg(args, char *);
|
|
||||||
if (!s)
|
|
||||||
{
|
|
||||||
s = "(NULL)";
|
|
||||||
}
|
|
||||||
|
|
||||||
for (len = 0; (len != field_width) && (s[len] != '\0'); len++);
|
|
||||||
|
|
||||||
if (precision > 0 && len > precision)
|
|
||||||
{
|
|
||||||
len = precision;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!(flags & LEFT))
|
|
||||||
{
|
|
||||||
while (len < field_width--)
|
|
||||||
{
|
|
||||||
if (str < end) *str = ' ';
|
|
||||||
++ str;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; i < len; ++i)
|
|
||||||
{
|
|
||||||
if (str < end) *str = *s;
|
|
||||||
++ str;
|
|
||||||
++ s;
|
|
||||||
}
|
|
||||||
|
|
||||||
while (len < field_width--)
|
|
||||||
{
|
|
||||||
if (str < end) *str = ' ';
|
|
||||||
++ str;
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
|
|
||||||
case 'p':
|
|
||||||
if (field_width == -1)
|
|
||||||
{
|
|
||||||
field_width = sizeof(void *) << 1;
|
|
||||||
field_width += 2; /* `0x` prefix */
|
|
||||||
flags |= SPECIAL;
|
|
||||||
flags |= ZEROPAD;
|
|
||||||
}
|
|
||||||
str = print_number(str, end, (unsigned long)va_arg(args, void *),
|
|
||||||
16, qualifier, field_width, precision, flags);
|
|
||||||
continue;
|
|
||||||
|
|
||||||
case '%':
|
|
||||||
if (str < end)
|
|
||||||
{
|
|
||||||
*str = '%';
|
|
||||||
}
|
|
||||||
++ str;
|
|
||||||
continue;
|
|
||||||
|
|
||||||
/* integer number formats - set up the flags and "break" */
|
|
||||||
case 'b':
|
|
||||||
base = 2;
|
|
||||||
break;
|
|
||||||
case 'o':
|
|
||||||
base = 8;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'X':
|
|
||||||
flags |= LARGE;
|
|
||||||
case 'x':
|
|
||||||
base = 16;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'd':
|
|
||||||
case 'i':
|
|
||||||
flags |= SIGN;
|
|
||||||
case 'u':
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'e':
|
|
||||||
case 'E':
|
|
||||||
case 'G':
|
|
||||||
case 'g':
|
|
||||||
case 'f':
|
|
||||||
case 'F':
|
|
||||||
va_arg(args, double);
|
|
||||||
default:
|
|
||||||
if (str < end)
|
|
||||||
{
|
|
||||||
*str = '%';
|
|
||||||
}
|
|
||||||
++ str;
|
|
||||||
|
|
||||||
if (*fmt)
|
|
||||||
{
|
|
||||||
if (str < end)
|
|
||||||
{
|
|
||||||
*str = *fmt;
|
|
||||||
}
|
|
||||||
++ str;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
-- fmt;
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (qualifier == 'L')
|
|
||||||
{
|
|
||||||
num = va_arg(args, unsigned long long);
|
|
||||||
}
|
|
||||||
else if (qualifier == 'l')
|
|
||||||
{
|
|
||||||
num = va_arg(args, unsigned long);
|
|
||||||
}
|
|
||||||
else if (qualifier == 'H')
|
|
||||||
{
|
|
||||||
num = (rt_int8_t)va_arg(args, rt_int32_t);
|
|
||||||
if (flags & SIGN)
|
|
||||||
{
|
|
||||||
num = (rt_int8_t)num;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (qualifier == 'h')
|
|
||||||
{
|
|
||||||
num = (rt_uint16_t)va_arg(args, rt_int32_t);
|
|
||||||
if (flags & SIGN)
|
|
||||||
{
|
|
||||||
num = (rt_int16_t)num;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (qualifier == 'z')
|
|
||||||
{
|
|
||||||
num = va_arg(args, rt_size_t);
|
|
||||||
if (flags & SIGN)
|
|
||||||
{
|
|
||||||
num = (rt_ssize_t)num;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
num = (rt_uint32_t)va_arg(args, unsigned long);
|
|
||||||
}
|
|
||||||
str = print_number(str, end, num, base, qualifier, field_width, precision, flags);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (size > 0)
|
|
||||||
{
|
|
||||||
if (str < end)
|
|
||||||
{
|
|
||||||
*str = '\0';
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
end[-1] = '\0';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* the trailing null byte doesn't count towards the total
|
|
||||||
* ++str;
|
|
||||||
*/
|
|
||||||
return str - buf;
|
|
||||||
}
|
|
||||||
RTM_EXPORT(rt_vsnprintf);
|
|
||||||
#if (defined(__GNUC__) && !defined(__ARMCC_VERSION) /* GCC */) && (__GNUC__ >= 7)
|
|
||||||
#pragma GCC diagnostic pop /* ignored "-Wimplicit-fallthrough" */
|
|
||||||
#endif /* (defined(__GNUC__) && !defined(__ARMCC_VERSION)) && (__GNUC__ >= 7 */
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief This function will fill a formatted string to buffer.
|
* @brief This function will fill a formatted string to buffer.
|
||||||
*
|
*
|
||||||
|
|
|
@ -13,14 +13,6 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#endif /* RT_KLIBC_USING_STDLIB */
|
#endif /* RT_KLIBC_USING_STDLIB */
|
||||||
|
|
||||||
#define DBG_TAG "kernel.string"
|
|
||||||
#ifdef RT_DEBUG_DEVICE
|
|
||||||
#define DBG_LVL DBG_LOG
|
|
||||||
#else
|
|
||||||
#define DBG_LVL DBG_WARNING
|
|
||||||
#endif /* defined (RT_DEBUG_DEVICE) */
|
|
||||||
#include <rtdbg.h>
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief This function will set the content of memory to specified value.
|
* @brief This function will set the content of memory to specified value.
|
||||||
*
|
*
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,616 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2006-2024, RT-Thread Development Team
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*
|
||||||
|
* Change Logs:
|
||||||
|
* Date Author Notes
|
||||||
|
* 2024-11-19 Meco Man the first version
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <rtthread.h>
|
||||||
|
|
||||||
|
#ifndef RT_KLIBC_USING_VSNPRINTF_STANDARD
|
||||||
|
|
||||||
|
#define _ISDIGIT(c) ((unsigned)((c) - '0') < 10)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function will duplicate a string.
|
||||||
|
*
|
||||||
|
* @param n is the string to be duplicated.
|
||||||
|
*
|
||||||
|
* @param base is support divide instructions value.
|
||||||
|
*
|
||||||
|
* @return the duplicated string pointer.
|
||||||
|
*/
|
||||||
|
#ifdef RT_KLIBC_USING_VSNPRINTF_LONGLONG
|
||||||
|
rt_inline int divide(unsigned long long *n, int base)
|
||||||
|
#else
|
||||||
|
rt_inline int divide(unsigned long *n, int base)
|
||||||
|
#endif /* RT_KLIBC_USING_VSNPRINTF_LONGLONG */
|
||||||
|
{
|
||||||
|
int res;
|
||||||
|
|
||||||
|
/* optimized for processor which does not support divide instructions. */
|
||||||
|
#ifdef RT_KLIBC_USING_VSNPRINTF_LONGLONG
|
||||||
|
res = (int)((*n) % base);
|
||||||
|
*n = (long long)((*n) / base);
|
||||||
|
#else
|
||||||
|
res = (int)((*n) % base);
|
||||||
|
*n = (long)((*n) / base);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
rt_inline int skip_atoi(const char **s)
|
||||||
|
{
|
||||||
|
int i = 0;
|
||||||
|
while (_ISDIGIT(**s))
|
||||||
|
i = i * 10 + *((*s)++) - '0';
|
||||||
|
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
#define ZEROPAD (1 << 0) /* pad with zero */
|
||||||
|
#define SIGN (1 << 1) /* unsigned/signed long */
|
||||||
|
#define PLUS (1 << 2) /* show plus */
|
||||||
|
#define SPACE (1 << 3) /* space if plus */
|
||||||
|
#define LEFT (1 << 4) /* left justified */
|
||||||
|
#define SPECIAL (1 << 5) /* 0x */
|
||||||
|
#define LARGE (1 << 6) /* use 'ABCDEF' instead of 'abcdef' */
|
||||||
|
|
||||||
|
static char *print_number(char *buf,
|
||||||
|
char *end,
|
||||||
|
#ifdef RT_KLIBC_USING_VSNPRINTF_LONGLONG
|
||||||
|
unsigned long long num,
|
||||||
|
#else
|
||||||
|
unsigned long num,
|
||||||
|
#endif /* RT_KLIBC_USING_VSNPRINTF_LONGLONG */
|
||||||
|
int base,
|
||||||
|
int qualifier,
|
||||||
|
int s,
|
||||||
|
int precision,
|
||||||
|
int type)
|
||||||
|
{
|
||||||
|
char c = 0, sign = 0;
|
||||||
|
#ifdef RT_KLIBC_USING_VSNPRINTF_LONGLONG
|
||||||
|
char tmp[64] = {0};
|
||||||
|
#else
|
||||||
|
char tmp[32] = {0};
|
||||||
|
#endif /* RT_KLIBC_USING_VSNPRINTF_LONGLONG */
|
||||||
|
int precision_bak = precision;
|
||||||
|
const char *digits = RT_NULL;
|
||||||
|
static const char small_digits[] = "0123456789abcdef";
|
||||||
|
static const char large_digits[] = "0123456789ABCDEF";
|
||||||
|
int i = 0;
|
||||||
|
int size = 0;
|
||||||
|
|
||||||
|
size = s;
|
||||||
|
|
||||||
|
digits = (type & LARGE) ? large_digits : small_digits;
|
||||||
|
if (type & LEFT)
|
||||||
|
{
|
||||||
|
type &= ~ZEROPAD;
|
||||||
|
}
|
||||||
|
|
||||||
|
c = (type & ZEROPAD) ? '0' : ' ';
|
||||||
|
|
||||||
|
/* get sign */
|
||||||
|
sign = 0;
|
||||||
|
if (type & SIGN)
|
||||||
|
{
|
||||||
|
switch (qualifier)
|
||||||
|
{
|
||||||
|
case 'h':
|
||||||
|
if ((rt_int16_t)num < 0)
|
||||||
|
{
|
||||||
|
sign = '-';
|
||||||
|
num = (rt_uint16_t)-num;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'L':
|
||||||
|
case 'l':
|
||||||
|
if ((long)num < 0)
|
||||||
|
{
|
||||||
|
sign = '-';
|
||||||
|
num = (unsigned long)-num;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 0:
|
||||||
|
default:
|
||||||
|
if ((rt_int32_t)num < 0)
|
||||||
|
{
|
||||||
|
sign = '-';
|
||||||
|
num = (rt_uint32_t)-num;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sign != '-')
|
||||||
|
{
|
||||||
|
if (type & PLUS)
|
||||||
|
{
|
||||||
|
sign = '+';
|
||||||
|
}
|
||||||
|
else if (type & SPACE)
|
||||||
|
{
|
||||||
|
sign = ' ';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (type & SPECIAL)
|
||||||
|
{
|
||||||
|
if (base == 2 || base == 16)
|
||||||
|
{
|
||||||
|
size -= 2;
|
||||||
|
}
|
||||||
|
else if (base == 8)
|
||||||
|
{
|
||||||
|
size--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
if (num == 0)
|
||||||
|
{
|
||||||
|
tmp[i++] = '0';
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
while (num != 0)
|
||||||
|
tmp[i++] = digits[divide(&num, base)];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (i > precision)
|
||||||
|
{
|
||||||
|
precision = i;
|
||||||
|
}
|
||||||
|
size -= precision;
|
||||||
|
|
||||||
|
if (!(type & (ZEROPAD | LEFT)))
|
||||||
|
{
|
||||||
|
if ((sign) && (size > 0))
|
||||||
|
{
|
||||||
|
size--;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (size-- > 0)
|
||||||
|
{
|
||||||
|
if (buf < end)
|
||||||
|
{
|
||||||
|
*buf = ' ';
|
||||||
|
}
|
||||||
|
|
||||||
|
++ buf;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sign)
|
||||||
|
{
|
||||||
|
if (buf < end)
|
||||||
|
{
|
||||||
|
*buf = sign;
|
||||||
|
}
|
||||||
|
-- size;
|
||||||
|
++ buf;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (type & SPECIAL)
|
||||||
|
{
|
||||||
|
if (base == 2)
|
||||||
|
{
|
||||||
|
if (buf < end)
|
||||||
|
*buf = '0';
|
||||||
|
++ buf;
|
||||||
|
if (buf < end)
|
||||||
|
*buf = 'b';
|
||||||
|
++ buf;
|
||||||
|
}
|
||||||
|
else if (base == 8)
|
||||||
|
{
|
||||||
|
if (buf < end)
|
||||||
|
*buf = '0';
|
||||||
|
++ buf;
|
||||||
|
}
|
||||||
|
else if (base == 16)
|
||||||
|
{
|
||||||
|
if (buf < end)
|
||||||
|
{
|
||||||
|
*buf = '0';
|
||||||
|
}
|
||||||
|
|
||||||
|
++ buf;
|
||||||
|
if (buf < end)
|
||||||
|
{
|
||||||
|
*buf = type & LARGE ? 'X' : 'x';
|
||||||
|
}
|
||||||
|
++ buf;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* no align to the left */
|
||||||
|
if (!(type & LEFT))
|
||||||
|
{
|
||||||
|
while (size-- > 0)
|
||||||
|
{
|
||||||
|
if (buf < end)
|
||||||
|
{
|
||||||
|
*buf = c;
|
||||||
|
}
|
||||||
|
|
||||||
|
++ buf;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
while (i < precision--)
|
||||||
|
{
|
||||||
|
if (buf < end)
|
||||||
|
{
|
||||||
|
*buf = '0';
|
||||||
|
}
|
||||||
|
|
||||||
|
++ buf;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* put number in the temporary buffer */
|
||||||
|
while (i-- > 0 && (precision_bak != 0))
|
||||||
|
{
|
||||||
|
if (buf < end)
|
||||||
|
{
|
||||||
|
*buf = tmp[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
++ buf;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (size-- > 0)
|
||||||
|
{
|
||||||
|
if (buf < end)
|
||||||
|
{
|
||||||
|
*buf = ' ';
|
||||||
|
}
|
||||||
|
|
||||||
|
++ buf;
|
||||||
|
}
|
||||||
|
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if (defined(__GNUC__) && !defined(__ARMCC_VERSION) /* GCC */) && (__GNUC__ >= 7)
|
||||||
|
/* Disable "-Wimplicit-fallthrough" below GNUC V7 */
|
||||||
|
#pragma GCC diagnostic push
|
||||||
|
/* ignore warning: this statement may fall through */
|
||||||
|
#pragma GCC diagnostic ignored "-Wimplicit-fallthrough"
|
||||||
|
#endif /* (defined(__GNUC__) && !defined(__ARMCC_VERSION)) && (__GNUC__ >= 7 */
|
||||||
|
/**
|
||||||
|
* @brief This function will fill a formatted string to buffer.
|
||||||
|
*
|
||||||
|
* @param buf is the buffer to save formatted string.
|
||||||
|
*
|
||||||
|
* @param size is the size of buffer.
|
||||||
|
*
|
||||||
|
* @param fmt is the format parameters.
|
||||||
|
*
|
||||||
|
* @param args is a list of variable parameters.
|
||||||
|
*
|
||||||
|
* @return The number of characters actually written to buffer.
|
||||||
|
*/
|
||||||
|
int rt_vsnprintf(char *buf, rt_size_t size, const char *fmt, va_list args)
|
||||||
|
{
|
||||||
|
#ifdef RT_KLIBC_USING_VSNPRINTF_LONGLONG
|
||||||
|
unsigned long long num = 0;
|
||||||
|
#else
|
||||||
|
unsigned long num = 0;
|
||||||
|
#endif /* RT_KLIBC_USING_VSNPRINTF_LONGLONG */
|
||||||
|
int i = 0, len = 0;
|
||||||
|
char *str = RT_NULL, *end = RT_NULL, c = 0;
|
||||||
|
const char *s = RT_NULL;
|
||||||
|
|
||||||
|
rt_uint8_t base = 0; /* the base of number */
|
||||||
|
rt_uint8_t flags = 0; /* flags to print number */
|
||||||
|
rt_uint8_t qualifier = 0; /* 'h', 'l', or 'L' for integer fields */
|
||||||
|
rt_int32_t field_width = 0; /* width of output field */
|
||||||
|
int precision = 0; /* min. # of digits for integers and max for a string */
|
||||||
|
|
||||||
|
str = buf;
|
||||||
|
end = buf + size;
|
||||||
|
|
||||||
|
/* Make sure end is always >= buf */
|
||||||
|
if (end < buf)
|
||||||
|
{
|
||||||
|
end = ((char *) - 1);
|
||||||
|
size = end - buf;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (; *fmt ; ++fmt)
|
||||||
|
{
|
||||||
|
if (*fmt != '%')
|
||||||
|
{
|
||||||
|
if (str < end)
|
||||||
|
{
|
||||||
|
*str = *fmt;
|
||||||
|
}
|
||||||
|
|
||||||
|
++ str;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* process flags */
|
||||||
|
flags = 0;
|
||||||
|
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
/* skips the first '%' also */
|
||||||
|
++fmt;
|
||||||
|
if (*fmt == '-') flags |= LEFT;
|
||||||
|
else if (*fmt == '+') flags |= PLUS;
|
||||||
|
else if (*fmt == ' ') flags |= SPACE;
|
||||||
|
else if (*fmt == '#') flags |= SPECIAL;
|
||||||
|
else if (*fmt == '0') flags |= ZEROPAD;
|
||||||
|
else break;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* get field width */
|
||||||
|
field_width = -1;
|
||||||
|
if (_ISDIGIT(*fmt))
|
||||||
|
{
|
||||||
|
field_width = skip_atoi(&fmt);
|
||||||
|
}
|
||||||
|
else if (*fmt == '*')
|
||||||
|
{
|
||||||
|
++fmt;
|
||||||
|
/* it's the next argument */
|
||||||
|
field_width = va_arg(args, int);
|
||||||
|
if (field_width < 0)
|
||||||
|
{
|
||||||
|
field_width = -field_width;
|
||||||
|
flags |= LEFT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* get the precision */
|
||||||
|
precision = -1;
|
||||||
|
if (*fmt == '.')
|
||||||
|
{
|
||||||
|
++fmt;
|
||||||
|
if (_ISDIGIT(*fmt))
|
||||||
|
{
|
||||||
|
precision = skip_atoi(&fmt);
|
||||||
|
}
|
||||||
|
else if (*fmt == '*')
|
||||||
|
{
|
||||||
|
++fmt;
|
||||||
|
/* it's the next argument */
|
||||||
|
precision = va_arg(args, int);
|
||||||
|
}
|
||||||
|
if (precision < 0)
|
||||||
|
{
|
||||||
|
precision = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
qualifier = 0; /* get the conversion qualifier */
|
||||||
|
|
||||||
|
if (*fmt == 'h' || *fmt == 'l' ||
|
||||||
|
#ifdef RT_KLIBC_USING_VSNPRINTF_LONGLONG
|
||||||
|
*fmt == 'L' ||
|
||||||
|
#endif /* RT_KLIBC_USING_VSNPRINTF_LONGLONG */
|
||||||
|
*fmt == 'z')
|
||||||
|
{
|
||||||
|
qualifier = *fmt;
|
||||||
|
++fmt;
|
||||||
|
#ifdef RT_KLIBC_USING_VSNPRINTF_LONGLONG
|
||||||
|
if (qualifier == 'l' && *fmt == 'l')
|
||||||
|
{
|
||||||
|
qualifier = 'L';
|
||||||
|
++fmt;
|
||||||
|
}
|
||||||
|
#endif /* RT_KLIBC_USING_VSNPRINTF_LONGLONG */
|
||||||
|
if (qualifier == 'h' && *fmt == 'h')
|
||||||
|
{
|
||||||
|
qualifier = 'H';
|
||||||
|
++fmt;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* the default base */
|
||||||
|
base = 10;
|
||||||
|
|
||||||
|
switch (*fmt)
|
||||||
|
{
|
||||||
|
case 'c':
|
||||||
|
if (!(flags & LEFT))
|
||||||
|
{
|
||||||
|
while (--field_width > 0)
|
||||||
|
{
|
||||||
|
if (str < end) *str = ' ';
|
||||||
|
++ str;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* get character */
|
||||||
|
c = (rt_uint8_t)va_arg(args, int);
|
||||||
|
if (str < end)
|
||||||
|
{
|
||||||
|
*str = c;
|
||||||
|
}
|
||||||
|
++ str;
|
||||||
|
|
||||||
|
/* put width */
|
||||||
|
while (--field_width > 0)
|
||||||
|
{
|
||||||
|
if (str < end) *str = ' ';
|
||||||
|
++ str;
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
|
||||||
|
case 's':
|
||||||
|
s = va_arg(args, char *);
|
||||||
|
if (!s)
|
||||||
|
{
|
||||||
|
s = "(NULL)";
|
||||||
|
}
|
||||||
|
|
||||||
|
for (len = 0; (len != field_width) && (s[len] != '\0'); len++);
|
||||||
|
|
||||||
|
if (precision > 0 && len > precision)
|
||||||
|
{
|
||||||
|
len = precision;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(flags & LEFT))
|
||||||
|
{
|
||||||
|
while (len < field_width--)
|
||||||
|
{
|
||||||
|
if (str < end) *str = ' ';
|
||||||
|
++ str;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < len; ++i)
|
||||||
|
{
|
||||||
|
if (str < end) *str = *s;
|
||||||
|
++ str;
|
||||||
|
++ s;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (len < field_width--)
|
||||||
|
{
|
||||||
|
if (str < end) *str = ' ';
|
||||||
|
++ str;
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
|
||||||
|
case 'p':
|
||||||
|
if (field_width == -1)
|
||||||
|
{
|
||||||
|
field_width = sizeof(void *) << 1;
|
||||||
|
field_width += 2; /* `0x` prefix */
|
||||||
|
flags |= SPECIAL;
|
||||||
|
flags |= ZEROPAD;
|
||||||
|
}
|
||||||
|
str = print_number(str, end, (unsigned long)va_arg(args, void *),
|
||||||
|
16, qualifier, field_width, precision, flags);
|
||||||
|
continue;
|
||||||
|
|
||||||
|
case '%':
|
||||||
|
if (str < end)
|
||||||
|
{
|
||||||
|
*str = '%';
|
||||||
|
}
|
||||||
|
++ str;
|
||||||
|
continue;
|
||||||
|
|
||||||
|
/* integer number formats - set up the flags and "break" */
|
||||||
|
case 'b':
|
||||||
|
base = 2;
|
||||||
|
break;
|
||||||
|
case 'o':
|
||||||
|
base = 8;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'X':
|
||||||
|
flags |= LARGE;
|
||||||
|
case 'x':
|
||||||
|
base = 16;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'd':
|
||||||
|
case 'i':
|
||||||
|
flags |= SIGN;
|
||||||
|
case 'u':
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'e':
|
||||||
|
case 'E':
|
||||||
|
case 'G':
|
||||||
|
case 'g':
|
||||||
|
case 'f':
|
||||||
|
case 'F':
|
||||||
|
va_arg(args, double);
|
||||||
|
default:
|
||||||
|
if (str < end)
|
||||||
|
{
|
||||||
|
*str = '%';
|
||||||
|
}
|
||||||
|
++ str;
|
||||||
|
|
||||||
|
if (*fmt)
|
||||||
|
{
|
||||||
|
if (str < end)
|
||||||
|
{
|
||||||
|
*str = *fmt;
|
||||||
|
}
|
||||||
|
++ str;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
-- fmt;
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (qualifier == 'L')
|
||||||
|
{
|
||||||
|
num = va_arg(args, unsigned long long);
|
||||||
|
}
|
||||||
|
else if (qualifier == 'l')
|
||||||
|
{
|
||||||
|
num = va_arg(args, unsigned long);
|
||||||
|
}
|
||||||
|
else if (qualifier == 'H')
|
||||||
|
{
|
||||||
|
num = (rt_int8_t)va_arg(args, rt_int32_t);
|
||||||
|
if (flags & SIGN)
|
||||||
|
{
|
||||||
|
num = (rt_int8_t)num;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (qualifier == 'h')
|
||||||
|
{
|
||||||
|
num = (rt_uint16_t)va_arg(args, rt_int32_t);
|
||||||
|
if (flags & SIGN)
|
||||||
|
{
|
||||||
|
num = (rt_int16_t)num;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (qualifier == 'z')
|
||||||
|
{
|
||||||
|
num = va_arg(args, rt_size_t);
|
||||||
|
if (flags & SIGN)
|
||||||
|
{
|
||||||
|
num = (rt_ssize_t)num;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
num = (rt_uint32_t)va_arg(args, unsigned long);
|
||||||
|
}
|
||||||
|
str = print_number(str, end, num, base, qualifier, field_width, precision, flags);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (size > 0)
|
||||||
|
{
|
||||||
|
if (str < end)
|
||||||
|
{
|
||||||
|
*str = '\0';
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
end[-1] = '\0';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* the trailing null byte doesn't count towards the total
|
||||||
|
* ++str;
|
||||||
|
*/
|
||||||
|
return str - buf;
|
||||||
|
}
|
||||||
|
RTM_EXPORT(rt_vsnprintf);
|
||||||
|
#if (defined(__GNUC__) && !defined(__ARMCC_VERSION) /* GCC */) && (__GNUC__ >= 7)
|
||||||
|
#pragma GCC diagnostic pop /* ignored "-Wimplicit-fallthrough" */
|
||||||
|
#endif /* (defined(__GNUC__) && !defined(__ARMCC_VERSION)) && (__GNUC__ >= 7 */
|
||||||
|
|
||||||
|
#endif /* !RT_KLIBC_USING_VSNPRINTF_STANDARD */
|
Loading…
Reference in New Issue