diff --git a/CMakeLists.txt b/CMakeLists.txt index 2b7544dbaa..1d70f0c7a4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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() diff --git a/userspace/common/strlcpy.h b/userspace/common/strlcpy.h index 7a9f44360c..8a15d40513 100644 --- a/userspace/common/strlcpy.h +++ b/userspace/common/strlcpy.h @@ -17,12 +17,15 @@ limitations under the License. #include #include +#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) { @@ -40,3 +43,4 @@ static inline size_t strlcpy(char *dst, const char *src, size_t size) { return srcsize; } +#endif