Skip to content

Commit 8d1a679

Browse files
committed
Check for strlcpy/strlcat
Some newer builds of glibc have strlcpy and strlcat defined, resulting in build failures on newer Linux distros. Rather than try to hard-code whether or not each version of each platform has strlcat and strlcpy, this patch has CMake check to see if it's available after including string.h. If they are, then we should not redefine them. This is a targeted change pulling the fix from the patch set merged in 5a1db79.
1 parent 19e5eb0 commit 8d1a679

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

CoreFoundation/Base.subproj/CoreFoundation_Prefix.h

+6-2
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,8 @@ static dispatch_queue_t __ ## PREFIX ## Queue(void) { \
189189
#define CF_RETAIN_BALANCED_ELSEWHERE(obj, identified_location) do { } while (0)
190190
#endif
191191

192-
#if (TARGET_OS_LINUX && !TARGET_OS_ANDROID && !TARGET_OS_CYGWIN) || TARGET_OS_WIN32
192+
#if !TARGET_OS_MAC
193+
#ifndef HAVE_STRLCPY
193194
CF_INLINE size_t
194195
strlcpy(char * dst, const char * src, size_t maxlen) {
195196
const size_t srclen = strlen(src);
@@ -201,7 +202,9 @@ strlcpy(char * dst, const char * src, size_t maxlen) {
201202
}
202203
return srclen;
203204
}
205+
#endif // !HAVE_STRLCPY
204206

207+
#ifndef HAVE_STRLCAT
205208
CF_INLINE size_t
206209
strlcat(char * dst, const char * src, size_t maxlen) {
207210
const size_t srclen = strlen(src);
@@ -215,7 +218,8 @@ strlcat(char * dst, const char * src, size_t maxlen) {
215218
}
216219
return dstlen + srclen;
217220
}
218-
#endif
221+
#endif // !HAVE_STRLCAT
222+
#endif // !TARGET_OS_MAC
219223

220224
#if TARGET_OS_WIN32
221225
// Compatibility with boolean.h

CoreFoundation/CMakeLists.txt

+12
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ project(CoreFoundation
66
VERSION 1338
77
LANGUAGES ASM C)
88

9+
include(CheckSymbolExists)
10+
911
set(CMAKE_C_STANDARD 99)
1012
set(CMAKE_C_STANDARD_REQUIRED YES)
1113

@@ -62,6 +64,16 @@ if(NOT "${CMAKE_C_SIMULATE_ID}" STREQUAL "MSVC")
6264
add_compile_options($<$<COMPILE_LANGUAGE:C>:-Werror=implicit-function-declaration>)
6365
endif()
6466

67+
check_symbol_exists("strlcat" "string.h" HAVE_STRLCAT)
68+
check_symbol_exists("strlcpy" "string.h" HAVE_STRLCPY)
69+
70+
if(HAVE_STRLCAT)
71+
add_compile_definitions($<$<COMPILE_LANGUAGE:C>:HAVE_STRLCAT>)
72+
endif()
73+
if(HAVE_STRLCPY)
74+
add_compile_definitions($<$<COMPILE_LANGUAGE:C>:HAVE_STRLCPY>)
75+
endif()
76+
6577
if(CF_DEPLOYMENT_SWIFT)
6678
add_compile_options($<$<COMPILE_LANGUAGE:C>:$<$<STREQUAL:${CMAKE_C_SIMULATE_ID},MSVC>:/clang:>-fcf-runtime-abi=swift>)
6779
endif()

0 commit comments

Comments
 (0)