Skip to content

Use CMake to check for strlcat/strlcpy #4860

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

Closed
Closed
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: 4 additions & 2 deletions CoreFoundation/Base.subproj/CoreFoundation_Prefix.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ static dispatch_queue_t __ ## PREFIX ## Queue(void) { \
#define CF_RETAIN_BALANCED_ELSEWHERE(obj, identified_location) do { } while (0)
#endif

#if (TARGET_OS_LINUX && !TARGET_OS_ANDROID && !TARGET_OS_CYGWIN) || TARGET_OS_WIN32
#ifndef HAVE_STRING_STRLCPY
CF_INLINE size_t
strlcpy(char * dst, const char * src, size_t maxlen) {
const size_t srclen = strlen(src);
Expand All @@ -201,7 +201,9 @@ strlcpy(char * dst, const char * src, size_t maxlen) {
}
return srclen;
}
#endif // HAVE_STRING_STRLCPY

#ifndef HAVE_STRING_STRLCAT
CF_INLINE size_t
strlcat(char * dst, const char * src, size_t maxlen) {
const size_t srclen = strlen(src);
Expand All @@ -215,7 +217,7 @@ strlcat(char * dst, const char * src, size_t maxlen) {
}
return dstlen + srclen;
}
#endif
#endif // HAVE_STRING_STRLCAT

#if TARGET_OS_WIN32
// Compatibility with boolean.h
Expand Down
12 changes: 11 additions & 1 deletion CoreFoundation/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,21 @@ if(CF_DEPLOYMENT_SWIFT)
add_compile_options($<$<COMPILE_LANGUAGE:C>:$<$<STREQUAL:${CMAKE_C_SIMULATE_ID},MSVC>:/clang:>-fcf-runtime-abi=swift>)
endif()

include(CheckSymbolExists)
check_symbol_exists("strlcat" "string.h" HAVE_STRING_STRLCAT)
if(HAVE_STRING_STRLCAT)
add_compile_definitions($<$<COMPILE_LANGUAGE:C>:HAVE_STRING_STRLCAT>)
endif()

check_symbol_exists("strlcpy" "string.h" HAVE_STRING_STRLCPY)
if(HAVE_STRING_STRLCPY)
add_compile_definitions($<$<COMPILE_LANGUAGE:C>:HAVE_STRING_STRLCPY>)
endif()

if(CMAKE_SYSTEM_NAME STREQUAL Linux OR CMAKE_SYSTEM_NAME STREQUAL Android)
add_compile_definitions($<$<COMPILE_LANGUAGE:C>:_GNU_SOURCE>)

if(CMAKE_SYSTEM_NAME STREQUAL Linux)
include(CheckSymbolExists)
include(CheckIncludeFile)
list(APPEND CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE)
check_include_file("sched.h" HAVE_SCHED_H)
Expand Down