Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't define strlcpy on musl libc #110

Merged
merged 1 commit into from
Nov 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,9 @@ if(CREATE_TEST_TARGETS AND NOT WIN32)
COMMAND ${CMAKE_MAKE_PROGRAM} run-unit-test-libsinsp
)
endif()

include(CheckSymbolExists)
check_symbol_exists(strlcpy "string.h" HAVE_STRLCPY)
if(HAVE_STRLCPY)
add_definitions(-DHAVE_STRLCPY)
endif()
4 changes: 4 additions & 0 deletions userspace/common/strlcpy.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,15 @@ limitations under the License.
#include <sys/types.h>
#include <string.h>

#pragma once

/*!
\brief Copy up to size - 1 characters from the NUL-terminated string src to dst, NUL-terminating the result.

\return The length of the source string.
*/

#ifndef HAVE_STRLCPY
static inline size_t strlcpy(char *dst, const char *src, size_t size) {
size_t srcsize = strlen(src);
if (size == 0) {
Expand All @@ -40,3 +43,4 @@ static inline size_t strlcpy(char *dst, const char *src, size_t size) {

return srcsize;
}
#endif