summaryrefslogtreecommitdiff
path: root/src/klibc
diff options
context:
space:
mode:
authorMeco Man <[email protected]>2024-11-25 00:43:12 -0500
committerRbb666 <[email protected]>2024-11-25 14:28:36 +0800
commit9afe6a51826fb84de229de220dab2077aa5734b2 (patch)
tree9d1b4a03e269c391d71dfc26f0bcc14375ffd8b1 /src/klibc
parentf849afb5ca40f4843d86d6bd55253b2db57a7ad4 (diff)
[klibc] separate klibc Kconfig
Diffstat (limited to 'src/klibc')
-rw-r--r--src/klibc/Kconfig250
-rw-r--r--src/klibc/SConscript11
-rw-r--r--src/klibc/kstdio.c20
-rw-r--r--src/klibc/kstring.c87
-rw-r--r--src/klibc/rt_vsnprintf_std.c5
-rw-r--r--src/klibc/rt_vsnprintf_tiny.c5
6 files changed, 341 insertions, 37 deletions
diff --git a/src/klibc/Kconfig b/src/klibc/Kconfig
new file mode 100644
index 0000000000..6baafd24e1
--- /dev/null
+++ b/src/klibc/Kconfig
@@ -0,0 +1,250 @@
+menu "klibc options"
+
+ comment "------------rt_memset options------------"
+ config RT_KLIBC_USING_USER_MEMSET
+ bool "Enable rt_memset to use user-defined version"
+ default n
+
+ if !RT_KLIBC_USING_USER_MEMSET
+ config RT_KLIBC_USING_LIBC_MEMSET
+ bool "Enable rt_memset to use libc memset"
+ default n
+
+ config RT_KLIBC_USING_TINY_MEMSET
+ bool "Enable rt_memset to use tiny version"
+ depends on !RT_KLIBC_USING_LIBC_MEMSET
+ default n
+ endif
+
+ comment "------------rt_memcpy options------------"
+ config RT_KLIBC_USING_USER_MEMCPY
+ bool "Enable rt_memcpy to use user-defined version"
+ default n
+
+ if !RT_KLIBC_USING_USER_MEMCPY
+ config RT_KLIBC_USING_LIBC_MEMCPY
+ bool "Enable rt_memcpy to use libc memcpy"
+ default n
+
+ config RT_KLIBC_USING_TINY_MEMCPY
+ bool "Enable rt_memcpy to use tiny version"
+ depends on !RT_KLIBC_USING_LIBC_MEMCPY
+ default n
+ endif
+
+ comment "------------rt_memmove options------------"
+ config RT_KLIBC_USING_USER_MEMMOVE
+ bool "Enable rt_memmove to use user-defined version"
+ default n
+
+ if !RT_KLIBC_USING_USER_MEMMOVE
+ config RT_KLIBC_USING_LIBC_MEMMOVE
+ bool "Enable rt_memmove to use libc memmove"
+ default n
+ endif
+
+ comment "------------rt_memcmp options------------"
+ config RT_KLIBC_USING_USER_MEMCMP
+ bool "Enable rt_memcmp to use user-defined version"
+ default n
+
+ if !RT_KLIBC_USING_USER_MEMCMP
+ config RT_KLIBC_USING_LIBC_MEMCMP
+ bool "Enable rt_memcmp to use libc memcmp"
+ default n
+ endif
+
+ comment "------------rt_strstr options------------"
+ config RT_KLIBC_USING_USER_STRSTR
+ bool "Enable rt_strstr to use user-defined version"
+ default n
+
+ if !RT_KLIBC_USING_USER_STRSTR
+ config RT_KLIBC_USING_LIBC_STRSTR
+ bool "Enable rt_strstr to use libc strstr"
+ default n
+ endif
+
+ comment "------------rt_strcasecmp options------------"
+ config RT_KLIBC_USING_USER_STRCASECMP
+ bool "Enable rt_strcasecmp to use user-defined version"
+ default n
+
+ comment "------------rt_strncpy options------------"
+ config RT_KLIBC_USING_USER_STRNCPY
+ bool "Enable rt_strncpy to use user-defined version"
+ default n
+
+ if !RT_KLIBC_USING_USER_STRNCPY
+ config RT_KLIBC_USING_LIBC_STRNCPY
+ bool "Enable rt_strncpy to use libc strncpy"
+ default n
+ endif
+
+ comment "------------rt_strcpy options------------"
+ config RT_KLIBC_USING_USER_STRCPY
+ bool "Enable rt_strcpy to use user-defined version"
+ default n
+
+ if !RT_KLIBC_USING_USER_STRCPY
+ config RT_KLIBC_USING_LIBC_STRCPY
+ bool "Enable rt_strcpy to use libc strcpy"
+ default n
+ endif
+
+ comment "------------rt_strncmp options------------"
+ config RT_KLIBC_USING_USER_STRNCMP
+ bool "Enable rt_strncmp to use user-defined version"
+ default n
+
+ if !RT_KLIBC_USING_USER_STRNCMP
+ config RT_KLIBC_USING_LIBC_STRNCMP
+ bool "Enable rt_strncmp to use libc strncmp"
+ default n
+ endif
+
+ comment "------------rt_strcmp options------------"
+ config RT_KLIBC_USING_USER_STRCMP
+ bool "Enable rt_strcmp to use user-defined version"
+ default n
+
+ if !RT_KLIBC_USING_USER_STRCMP
+ config RT_KLIBC_USING_LIBC_STRCMP
+ bool "Enable rt_strcmp to use libc strcmp"
+ default n
+ endif
+
+ comment "------------rt_strlen options------------"
+ config RT_KLIBC_USING_USER_STRLEN
+ bool "Enable rt_strlen to use user-defined version"
+ default n
+
+ if !RT_KLIBC_USING_USER_STRLEN
+ config RT_KLIBC_USING_LIBC_STRLEN
+ bool "Enable rt_strlen to use libc strlen"
+ default n
+ endif
+
+ comment "------------rt_strlen options------------"
+ config RT_KLIBC_USING_USER_STRLEN
+ bool "Enable rt_strlen to use user-defined version"
+ default n
+
+ if !RT_KLIBC_USING_USER_STRLEN
+ config RT_KLIBC_USING_LIBC_STRLEN
+ bool "Enable rt_strlen to use libc strlen"
+ default n
+ endif
+
+ comment "------------rt_strnlen options------------"
+ config RT_KLIBC_USING_USER_STRNLEN
+ bool "Enable rt_strnlen to use user-defined version"
+ default n
+
+ comment "------------rt_vsscanf options------------"
+ config RT_KLIBC_USING_LIBC_VSSCANF
+ bool "Enable rt_vsscanf to use libc vsscanf"
+ default n
+
+ comment "------------rt_vsnprintf options------------"
+ config RT_KLIBC_USING_LIBC_VSNPRINTF
+ bool "Enable rt_vsnprintf to use libc vsscanf"
+ default n
+
+ config RT_KLIBC_USING_VSNPRINTF_LONGLONG
+ bool "Enable rt_vsnprintf function to support long-long format"
+ depends on !RT_KLIBC_USING_LIBC_VSNPRINTF
+ 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.
+
+ menuconfig RT_KLIBC_USING_VSNPRINTF_STANDARD
+ bool "Enable standard rt_vsnprintf version"
+ default y if ARCH_CPU_64BIT
+ default n
+ select RT_KLIBC_USING_VSNPRINTF_LONGLONG
+ depends on !RT_KLIBC_USING_LIBC_VSNPRINTF
+ help
+ Standard version of rt_vsnprintf, which is full function but higher stack usage.
+
+ 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
diff --git a/src/klibc/SConscript b/src/klibc/SConscript
index 4a17403c20..eb629ef725 100644
--- a/src/klibc/SConscript
+++ b/src/klibc/SConscript
@@ -2,7 +2,16 @@ from building import *
import os
cwd = GetCurrentDir()
-src = Glob('*.c')
+src = ['kerrno.c', 'kstdio.c', 'kstring.c']
+
+if not GetDepend(['RT_KLIBC_USING_LIBC_VSNPRINTF']):
+ if GetDepend(['RT_KLIBC_USING_VSNPRINTF_STANDARD']):
+ src += ['rt_vsnprintf_std.c']
+ else:
+ src += ['rt_vsnprintf_tiny.c']
+
+if not GetDepend(['RT_KLIBC_USING_LIBC_VSSCANF']):
+ src += ['rt_vsscanf.c']
group = DefineGroup('klibc', src, depend = [''])
diff --git a/src/klibc/kstdio.c b/src/klibc/kstdio.c
index ceb891f325..df73eab49b 100644
--- a/src/klibc/kstdio.c
+++ b/src/klibc/kstdio.c
@@ -9,6 +9,10 @@
*/
#include <rtthread.h>
+#if defined(RT_KLIBC_USING_LIBC_VSSCANF) || \
+ defined(RT_KLIBC_USING_LIBC_VSNPRINTF)
+#include <stdio.h>
+#endif
/**
* @brief This function will fill a formatted string to buffer.
@@ -73,6 +77,22 @@ int rt_sprintf(char *buf, const char *format, ...)
}
RTM_EXPORT(rt_sprintf);
+#ifdef RT_KLIBC_USING_LIBC_VSNPRINTF
+int rt_vsnprintf(char *buf, rt_size_t size, const char *fmt, va_list args)
+{
+ return vsnprintf(buf, size, fmt, args);
+}
+#endif /* RT_KLIBC_USING_LIBC_VSNPRINTF */
+RTM_EXPORT(rt_vsnprintf);
+
+#ifdef RT_KLIBC_USING_LIBC_VSSCANF
+int rt_vsscanf(const char *buffer, const char *format, va_list ap)
+{
+ return vsscanf(buffer, format, ap);
+}
+#endif /* RT_KLIBC_USING_LIBC_VSSCANF */
+RTM_EXPORT(rt_vsscanf);
+
/**
* @brief This function parses a formatted string from the input string.
*
diff --git a/src/klibc/kstring.c b/src/klibc/kstring.c
index 9eba5e5710..d2988d629c 100644
--- a/src/klibc/kstring.c
+++ b/src/klibc/kstring.c
@@ -9,9 +9,19 @@
*/
#include <rtthread.h>
-#ifdef RT_KLIBC_USING_STDLIB
+
+#if defined(RT_KLIBC_USING_LIBC_MEMSET) || \
+ defined(RT_KLIBC_USING_LIBC_MEMCPY) || \
+ defined(RT_KLIBC_USING_LIBC_MEMMOVE) || \
+ defined(RT_KLIBC_USING_LIBC_MEMCMP) || \
+ defined(RT_KLIBC_USING_LIBC_STRSTR) || \
+ defined(RT_KLIBC_USING_LIBC_STRNCPY) || \
+ defined(RT_KLIBC_USING_LIBC_STRCPY) || \
+ defined(RT_KLIBC_USING_LIBC_STRNCMP) || \
+ defined(RT_KLIBC_USING_LIBC_STRCMP) || \
+ defined(RT_KLIBC_USING_LIBC_STRLEN)
#include <string.h>
-#endif /* RT_KLIBC_USING_STDLIB */
+#endif
/**
* @brief This function will set the content of memory to specified value.
@@ -25,11 +35,12 @@
*
* @return The address of source memory.
*/
-rt_weak void *rt_memset(void *s, int c, rt_ubase_t count)
+#ifndef RT_KLIBC_USING_USER_MEMSET
+void *rt_memset(void *s, int c, rt_ubase_t count)
{
-#if defined(RT_KLIBC_USING_STDLIB_MEMORY)
+#if defined(RT_KLIBC_USING_LIBC_MEMSET)
return memset(s, c, count);
-#elif defined(RT_KLIBC_USING_TINY_SIZE)
+#elif defined(RT_KLIBC_USING_TINY_MEMSET)
char *xs = (char *)s;
while (count--)
@@ -37,6 +48,7 @@ rt_weak void *rt_memset(void *s, int c, rt_ubase_t count)
return s;
#else
+
#define LBLOCKSIZE (sizeof(rt_ubase_t))
#define UNALIGNED(X) ((long)X & (LBLOCKSIZE - 1))
#define TOO_SMALL(LEN) ((LEN) < LBLOCKSIZE)
@@ -92,8 +104,9 @@ rt_weak void *rt_memset(void *s, int c, rt_ubase_t count)
#undef LBLOCKSIZE
#undef UNALIGNED
#undef TOO_SMALL
-#endif /* RT_KLIBC_USING_STDLIB_MEMORY */
+#endif /* RT_KLIBC_USING_LIBC_MEMSET */
}
+#endif /* RT_KLIBC_USING_USER_MEMSET */
RTM_EXPORT(rt_memset);
/**
@@ -107,11 +120,12 @@ RTM_EXPORT(rt_memset);
*
* @return The address of destination memory
*/
-rt_weak void *rt_memcpy(void *dst, const void *src, rt_ubase_t count)
+#ifndef RT_KLIBC_USING_USER_MEMCPY
+void *rt_memcpy(void *dst, const void *src, rt_ubase_t count)
{
-#if defined(RT_KLIBC_USING_STDLIB_MEMORY)
+#if defined(RT_KLIBC_USING_LIBC_MEMCPY)
return memcpy(dst, src, count);
-#elif defined(RT_KLIBC_USING_TINY_SIZE)
+#elif defined(RT_KLIBC_USING_TINY_MEMCPY)
char *tmp = (char *)dst, *s = (char *)src;
rt_ubase_t len = 0;
@@ -178,8 +192,9 @@ rt_weak void *rt_memcpy(void *dst, const void *src, rt_ubase_t count)
#undef BIGBLOCKSIZE
#undef LITTLEBLOCKSIZE
#undef TOO_SMALL
-#endif /* RT_KLIBC_USING_STDLIB_MEMORY */
+#endif /* RT_KLIBC_USING_LIBC_MEMCPY */
}
+#endif /* RT_KLIBC_USING_USER_MEMCPY */
RTM_EXPORT(rt_memcpy);
/**
@@ -195,9 +210,10 @@ RTM_EXPORT(rt_memcpy);
*
* @return The address of destination memory.
*/
+#ifndef RT_KLIBC_USING_USER_MEMMOVE
void *rt_memmove(void *dest, const void *src, rt_size_t n)
{
-#ifdef RT_KLIBC_USING_STDLIB_MEMORY
+#ifdef RT_KLIBC_USING_LIBC_MEMMOVE
return memmove(dest, src, n);
#else
char *tmp = (char *)dest, *s = (char *)src;
@@ -217,8 +233,9 @@ void *rt_memmove(void *dest, const void *src, rt_size_t n)
}
return dest;
-#endif /* RT_KLIBC_USING_STDLIB_MEMORY */
+#endif /* RT_KLIBC_USING_LIBC_MEMMOVE */
}
+#endif /* RT_KLIBC_USING_USER_MEMMOVE */
RTM_EXPORT(rt_memmove);
/**
@@ -235,9 +252,10 @@ RTM_EXPORT(rt_memmove);
* If the result > 0, cs is greater than ct.
* If the result = 0, cs is equal to ct.
*/
+#ifndef RT_KLIBC_USING_USER_MEMCMP
rt_int32_t rt_memcmp(const void *cs, const void *ct, rt_size_t count)
{
-#ifdef RT_KLIBC_USING_STDLIB_MEMORY
+#ifdef RT_KLIBC_USING_LIBC_MEMCMP
return memcmp(cs, ct, count);
#else
const unsigned char *su1 = RT_NULL, *su2 = RT_NULL;
@@ -248,8 +266,9 @@ rt_int32_t rt_memcmp(const void *cs, const void *ct, rt_size_t count)
break;
return res;
-#endif /* RT_KLIBC_USING_STDLIB_MEMORY */
+#endif /* RT_KLIBC_USING_LIBC_MEMCMP */
}
+#endif /* RT_KLIBC_USING_USER_MEMCMP */
RTM_EXPORT(rt_memcmp);
/**
@@ -262,9 +281,10 @@ RTM_EXPORT(rt_memcmp);
*
* @return The first occurrence of a s2 in s1, or RT_NULL if no found.
*/
+#ifndef RT_KLIBC_USING_USER_STRSTR
char *rt_strstr(const char *s1, const char *s2)
{
-#ifdef RT_KLIBC_USING_STDLIB
+#ifdef RT_KLIBC_USING_LIBC_STRSTR
return strstr(s1, s2);
#else
int l1 = 0, l2 = 0;
@@ -288,8 +308,9 @@ char *rt_strstr(const char *s1, const char *s2)
}
return RT_NULL;
-#endif /* RT_KLIBC_USING_STDLIB */
+#endif /* RT_KLIBC_USING_LIBC_STRSTR */
}
+#endif /* RT_KLIBC_USING_USER_STRSTR */
RTM_EXPORT(rt_strstr);
/**
@@ -304,6 +325,7 @@ RTM_EXPORT(rt_strstr);
* If the result > 0, a is greater than a.
* If the result = 0, a is equal to a.
*/
+#ifndef RT_KLIBC_USING_USER_STRCASECMP
rt_int32_t rt_strcasecmp(const char *a, const char *b)
{
int ca = 0, cb = 0;
@@ -321,6 +343,7 @@ rt_int32_t rt_strcasecmp(const char *a, const char *b)
return ca - cb;
}
+#endif /* RT_KLIBC_USING_USER_STRCASECMP */
RTM_EXPORT(rt_strcasecmp);
/**
@@ -334,9 +357,10 @@ RTM_EXPORT(rt_strcasecmp);
*
* @return The address where the copied content is stored.
*/
+#ifndef RT_KLIBC_USING_USER_STRNCPY
char *rt_strncpy(char *dst, const char *src, rt_size_t n)
{
-#ifdef RT_KLIBC_USING_STDLIB
+#ifdef RT_KLIBC_USING_LIBC_STRNCPY
return strncpy(dst, src, n);
#else
if (n != 0)
@@ -360,8 +384,9 @@ char *rt_strncpy(char *dst, const char *src, rt_size_t n)
}
return (dst);
-#endif /* RT_KLIBC_USING_STDLIB */
+#endif /* RT_KLIBC_USING_LIBC_STRNCPY */
}
+#endif /* RT_KLIBC_USING_USER_STRNCPY */
RTM_EXPORT(rt_strncpy);
/**
@@ -373,9 +398,10 @@ RTM_EXPORT(rt_strncpy);
*
* @return The address where the copied content is stored.
*/
+#ifndef RT_KLIBC_USING_USER_STRCPY
char *rt_strcpy(char *dst, const char *src)
{
-#ifdef RT_KLIBC_USING_STDLIB
+#ifdef RT_KLIBC_USING_LIBC_STRCPY
return strcpy(dst, src);
#else
char *dest = dst;
@@ -389,8 +415,9 @@ char *rt_strcpy(char *dst, const char *src)
*dst = '\0';
return dest;
-#endif /* RT_KLIBC_USING_STDLIB */
+#endif /* RT_KLIBC_USING_LIBC_STRCPY */
}
+#endif /* RT_KLIBC_USING_USER_STRCPY */
RTM_EXPORT(rt_strcpy);
/**
@@ -407,9 +434,10 @@ RTM_EXPORT(rt_strcpy);
* If the result > 0, cs is greater than ct.
* If the result = 0, cs is equal to ct.
*/
+#ifndef RT_KLIBC_USING_USER_STRNCMP
rt_int32_t rt_strncmp(const char *cs, const char *ct, rt_size_t count)
{
-#ifdef RT_KLIBC_USING_STDLIB
+#ifdef RT_KLIBC_USING_LIBC_STRNCMP
return strncmp(cs, ct, count);
#else
signed char res = 0;
@@ -425,8 +453,9 @@ rt_int32_t rt_strncmp(const char *cs, const char *ct, rt_size_t count)
}
return res;
-#endif /* RT_KLIBC_USING_STDLIB */
+#endif /* RT_KLIBC_USING_LIBC_STRNCMP */
}
+#endif /* RT_KLIBC_USING_USER_STRNCMP */
RTM_EXPORT(rt_strncmp);
/**
@@ -441,9 +470,10 @@ RTM_EXPORT(rt_strncmp);
* If the result > 0, cs is greater than ct.
* If the result = 0, cs is equal to ct.
*/
+#ifndef RT_KLIBC_USING_USER_STRCMP
rt_int32_t rt_strcmp(const char *cs, const char *ct)
{
-#ifdef RT_KLIBC_USING_STDLIB
+#ifdef RT_KLIBC_USING_LIBC_STRCMP
return strcmp(cs, ct);
#else
while (*cs && *cs == *ct)
@@ -453,8 +483,9 @@ rt_int32_t rt_strcmp(const char *cs, const char *ct)
}
return (*cs - *ct);
-#endif /* RT_KLIBC_USING_STDLIB */
+#endif /* RT_KLIBC_USING_LIBC_STRCMP */
}
+#endif /* RT_KLIBC_USING_USER_STRCMP */
RTM_EXPORT(rt_strcmp);
/**
@@ -465,16 +496,18 @@ RTM_EXPORT(rt_strcmp);
*
* @return The length of string.
*/
+#ifndef RT_KLIBC_USING_USER_STRLEN
rt_size_t rt_strlen(const char *s)
{
-#ifdef RT_KLIBC_USING_STDLIB
+#ifdef RT_KLIBC_USING_LIBC_STRLEN
return strlen(s);
#else
const char *sc = RT_NULL;
for (sc = s; *sc != '\0'; ++sc);
return sc - s;
-#endif /* RT_KLIBC_USING_STDLIB */
+#endif /* RT_KLIBC_USING_LIBC_STRLEN */
}
+#endif /* RT_KLIBC_USING_USER_STRLEN */
RTM_EXPORT(rt_strlen);
/**
@@ -490,12 +523,14 @@ RTM_EXPORT(rt_strlen);
*
* @return The length of string.
*/
+#ifndef RT_KLIBC_USING_USER_STRNLEN
rt_size_t rt_strnlen(const char *s, rt_ubase_t maxlen)
{
const char *sc;
for (sc = s; *sc != '\0' && (rt_ubase_t)(sc - s) < maxlen; ++sc);
return sc - s;
}
+#endif /* RT_KLIBC_USING_USER_STRNLEN */
RTM_EXPORT(rt_strnlen);
#ifdef RT_USING_HEAP
diff --git a/src/klibc/rt_vsnprintf_std.c b/src/klibc/rt_vsnprintf_std.c
index 520061d277..583cfb715b 100644
--- a/src/klibc/rt_vsnprintf_std.c
+++ b/src/klibc/rt_vsnprintf_std.c
@@ -49,9 +49,6 @@
*/
#include <rtthread.h>
-
-#ifdef RT_KLIBC_USING_VSNPRINTF_STANDARD
-
#include <stdio.h>
#include <stdint.h>
#include <limits.h>
@@ -1352,5 +1349,3 @@ int rt_vsnprintf(char *buf, rt_size_t size, const char *fmt, va_list args)
output_gadget_t gadget = buffer_gadget(buf, size);
return vsnprintf_impl(&gadget, fmt, args);
}
-
-#endif /* RT_KLIBC_USING_VSNPRINTF_STANDARD */
diff --git a/src/klibc/rt_vsnprintf_tiny.c b/src/klibc/rt_vsnprintf_tiny.c
index a91e1498d5..75c89512d9 100644
--- a/src/klibc/rt_vsnprintf_tiny.c
+++ b/src/klibc/rt_vsnprintf_tiny.c
@@ -10,8 +10,6 @@
#include <rtthread.h>
-#ifndef RT_KLIBC_USING_VSNPRINTF_STANDARD
-
#define _ISDIGIT(c) ((unsigned)((c) - '0') < 10)
/**
@@ -608,9 +606,6 @@ int rt_vsnprintf(char *buf, rt_size_t size, const char *fmt, va_list args)
*/
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 */