diff --git a/Sources/TSCBasic/CMakeLists.txt b/Sources/TSCBasic/CMakeLists.txt index a1f5bcc2..d8b85eaa 100644 --- a/Sources/TSCBasic/CMakeLists.txt +++ b/Sources/TSCBasic/CMakeLists.txt @@ -52,8 +52,6 @@ add_library(TSCBasic misc.swift) target_compile_options(TSCBasic PUBLIC - # Don't use GNU strerror_r on Android. - "$<$:SHELL:-Xcc -U_GNU_SOURCE>" # Ignore secure function warnings on Windows. "$<$:SHELL:-Xcc -D_CRT_SECURE_NO_WARNINGS>") target_link_libraries(TSCBasic PRIVATE diff --git a/Sources/TSCBasic/misc.swift b/Sources/TSCBasic/misc.swift index 58a302de..d85dd096 100644 --- a/Sources/TSCBasic/misc.swift +++ b/Sources/TSCBasic/misc.swift @@ -8,6 +8,7 @@ See http://swift.org/CONTRIBUTORS.txt for Swift project authors */ +@_implementationOnly import TSCclibc import TSCLibc import Foundation #if os(Windows) @@ -327,7 +328,7 @@ extension SystemError: CustomStringConvertible { var cap = 64 while cap <= 16 * 1024 { var buf = [Int8](repeating: 0, count: cap) - let err = TSCLibc.strerror_r(errno, &buf, buf.count) + let err = TSCclibc.tsc_strerror_r(errno, &buf, buf.count) if err == EINVAL { return "Unknown error \(errno)" } diff --git a/Sources/TSCclibc/CMakeLists.txt b/Sources/TSCclibc/CMakeLists.txt index bbeb1911..e28860c2 100644 --- a/Sources/TSCclibc/CMakeLists.txt +++ b/Sources/TSCclibc/CMakeLists.txt @@ -7,11 +7,12 @@ # See http://swift.org/CONTRIBUTORS.txt for Swift project authors add_library(TSCclibc STATIC - libc.c process.c) + libc.c process.c strerror.c) target_include_directories(TSCclibc PUBLIC include) target_compile_definitions(TSCclibc PRIVATE "$<$:_GNU_SOURCE>") +set_target_properties(TSCclibc PROPERTIES POSITION_INDEPENDENT_CODE YES) if(NOT BUILD_SHARED_LIBS) install(TARGETS TSCclibc diff --git a/Sources/TSCclibc/include/module.modulemap b/Sources/TSCclibc/include/module.modulemap index 82bddc8e..e3ee9bc8 100644 --- a/Sources/TSCclibc/include/module.modulemap +++ b/Sources/TSCclibc/include/module.modulemap @@ -2,5 +2,6 @@ module TSCclibc { header "TSCclibc.h" header "indexstore_functions.h" header "process.h" + header "strerror.h" export * } diff --git a/Sources/TSCclibc/include/strerror.h b/Sources/TSCclibc/include/strerror.h new file mode 100644 index 00000000..ca03e2c5 --- /dev/null +++ b/Sources/TSCclibc/include/strerror.h @@ -0,0 +1,5 @@ +#include + +#ifndef _WIN32 +extern int tsc_strerror_r(int errnum, char *buf, size_t buflen); +#endif diff --git a/Sources/TSCclibc/strerror.c b/Sources/TSCclibc/strerror.c new file mode 100644 index 00000000..9dc082ad --- /dev/null +++ b/Sources/TSCclibc/strerror.c @@ -0,0 +1,9 @@ +#undef _GNU_SOURCE +#include "strerror.h" +#include + +#ifndef _WIN32 +int tsc_strerror_r(int errnum, char *buf, size_t buflen) { + return strerror_r(errnum, buf, buflen); +} +#endif