Skip to content

Commit ca4dc50

Browse files
galakcarlescufi
authored andcommittedMay 8, 2023
libc: Move strnlen into common
Move the strnlen implementation into common so its available to any libc that may not implement strnlen. Signed-off-by: Kumar Gala <kumar.gala@intel.com>
1 parent 8df8173 commit ca4dc50

File tree

7 files changed

+8
-20
lines changed

7 files changed

+8
-20
lines changed
 

‎cmake/toolchain/armclang/Kconfig

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ choice LIBC_IMPLEMENTATION
1515

1616
config ARMCLANG_STD_LIBC
1717
bool "ARM Compiler C library"
18+
select COMMON_LIBC_STRNLEN
1819
select COMMON_LIBC_TIME if POSIX_CLOCK
1920
help
2021
Use the full Arm Compiler runtime libraries.

‎lib/libc/Kconfig

+1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ config MINIMAL_LIBC
6565
depends on !REQUIRES_FULL_LIBC
6666
depends on MINIMAL_LIBC_SUPPORTED
6767
imply COMPILER_FREESTANDING
68+
select COMMON_LIBC_STRNLEN
6869
help
6970
Build with minimal C library.
7071

‎lib/libc/armstdc/CMakeLists.txt

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
zephyr_library()
44
zephyr_library_sources(src/errno.c)
5-
zephyr_library_sources(src/string.c)
65
zephyr_library_sources(src/libc-hooks.c)
76
zephyr_library_sources_ifndef(CONFIG_MULTITHREADING src/threading_weak.c)
87

‎lib/libc/common/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ zephyr_library()
44
zephyr_library_property(ALLOW_EMPTY TRUE)
55
zephyr_library_sources_ifdef(CONFIG_COMMON_LIBC_TIME source/time/time.c)
66
zephyr_library_sources_ifdef(CONFIG_COMMON_LIBC_MALLOC source/stdlib/malloc.c)
7+
zephyr_library_sources_ifdef(CONFIG_COMMON_LIBC_STRNLEN source/string/strnlen.c)

‎lib/libc/common/Kconfig

+5
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,8 @@ config COMMON_LIBC_REALLOCARRAY
3737
help
3838
Enable the common C library trivial implementation of
3939
reallocarray, which forwards to realloc.
40+
41+
config COMMON_LIBC_STRNLEN
42+
bool
43+
help
44+
common implementation of strnlen().
File renamed without changes.

‎lib/libc/minimal/source/string/string.c

-19
Original file line numberDiff line numberDiff line change
@@ -116,25 +116,6 @@ size_t strlen(const char *s)
116116
return n;
117117
}
118118

119-
/**
120-
*
121-
* @brief Get fixed-size string length
122-
*
123-
* @return number of bytes in fixed-size string <s>
124-
*/
125-
126-
size_t strnlen(const char *s, size_t maxlen)
127-
{
128-
size_t n = 0;
129-
130-
while (*s != '\0' && n < maxlen) {
131-
s++;
132-
n++;
133-
}
134-
135-
return n;
136-
}
137-
138119
/**
139120
*
140121
* @brief Compare two strings

0 commit comments

Comments
 (0)
Please sign in to comment.