Skip to content

Commit

Permalink
Merge pull request #4949 from etcwilde/ewilde/5.10/strlcpy-strlcat-check
Browse files Browse the repository at this point in the history
  • Loading branch information
shahmishal authored May 15, 2024
2 parents c66cb63 + 8d1a679 commit 1a538a2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
8 changes: 6 additions & 2 deletions CoreFoundation/Base.subproj/CoreFoundation_Prefix.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,8 @@ 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
#if !TARGET_OS_MAC
#ifndef HAVE_STRLCPY
CF_INLINE size_t
strlcpy(char * dst, const char * src, size_t maxlen) {
const size_t srclen = strlen(src);
Expand All @@ -201,7 +202,9 @@ strlcpy(char * dst, const char * src, size_t maxlen) {
}
return srclen;
}
#endif // !HAVE_STRLCPY

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

#if TARGET_OS_WIN32
// Compatibility with boolean.h
Expand Down
12 changes: 12 additions & 0 deletions CoreFoundation/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ project(CoreFoundation
VERSION 1338
LANGUAGES ASM C)

include(CheckSymbolExists)

set(CMAKE_C_STANDARD 99)
set(CMAKE_C_STANDARD_REQUIRED YES)

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

check_symbol_exists("strlcat" "string.h" HAVE_STRLCAT)
check_symbol_exists("strlcpy" "string.h" HAVE_STRLCPY)

if(HAVE_STRLCAT)
add_compile_definitions($<$<COMPILE_LANGUAGE:C>:HAVE_STRLCAT>)
endif()
if(HAVE_STRLCPY)
add_compile_definitions($<$<COMPILE_LANGUAGE:C>:HAVE_STRLCPY>)
endif()

if(CF_DEPLOYMENT_SWIFT)
add_compile_options($<$<COMPILE_LANGUAGE:C>:$<$<STREQUAL:${CMAKE_C_SIMULATE_ID},MSVC>:/clang:>-fcf-runtime-abi=swift>)
endif()
Expand Down

0 comments on commit 1a538a2

Please sign in to comment.