Skip to content

Commit 48076cb

Browse files
committed
[CoreFoundation][Build] Explicitly check for a few functions.
Use CMake to check for the existence of strlcpy(), strlcat() and issetugid() before using them. rdar://123381867
1 parent 80e95bb commit 48076cb

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

CoreFoundation/Base.subproj/CoreFoundation_Prefix.h

Lines changed: 6 additions & 2 deletions
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+
#if !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
204206

207+
#if !HAVE_STRLCAT
205208
CF_INLINE size_t
206209
strlcat(char * dst, const char * src, size_t maxlen) {
207210
const size_t srclen = strlen(src);
@@ -216,6 +219,7 @@ strlcat(char * dst, const char * src, size_t maxlen) {
216219
return dstlen + srclen;
217220
}
218221
#endif
222+
#endif // !TARGET_OS_MAC
219223

220224
#if TARGET_OS_WIN32
221225
// Compatibility with boolean.h
@@ -300,7 +304,7 @@ typedef unsigned long fd_mask;
300304
#endif
301305

302306

303-
#if !TARGET_OS_CYGWIN && !TARGET_OS_BSD
307+
#if !TARGET_OS_MAC && !HAVE_ISSETUGID
304308
#define issetugid() 0
305309
#endif
306310

CoreFoundation/CMakeLists.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,21 @@ elseif(CMAKE_SYSTEM_NAME STREQUAL Windows)
9090
endif()
9191
endif()
9292

93+
# Look for some functions that may not be present on all platforms
94+
check_symbol_exists(strlcpy "string.h" HAVE_STRLCPY)
95+
check_symbol_exists(strlcat "string.h" HAVE_STRLCAT)
96+
check_symbol_exists(issetugid "unistd.h" HAVE_ISSETUGID)
97+
98+
if(HAVE_STRLCPY)
99+
add_compile_definitions($<$<COMPILE_LANGUAGE:C>:HAVE_STRLCPY>)
100+
endif()
101+
if(HAVE_STRLCAT)
102+
add_compile_definitions($<$<COMPILE_LANGUAGE:C>:HAVE_STRLCAT>)
103+
endif()
104+
if(HAVE_ISSETUGID)
105+
add_compile_definitions($<$<COMPILE_LANGUAGE:C>:HAVE_ISSETUGID>)
106+
endif()
107+
93108
add_compile_definitions($<$<COMPILE_LANGUAGE:C>:U_SHOW_DRAFT_API>)
94109
add_compile_definitions($<$<COMPILE_LANGUAGE:C>:CF_BUILDING_CF>)
95110

0 commit comments

Comments
 (0)