Skip to content

Commit baa8180

Browse files
committed
Use C to force the POSIX (not GNU) overload of strerror_r to be selected
This allows building TSC for Android without needing to pass custom flags via -Xcc.
1 parent bd9e2de commit baa8180

File tree

6 files changed

+18
-4
lines changed

6 files changed

+18
-4
lines changed

Sources/TSCBasic/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,6 @@ add_library(TSCBasic
5252
misc.swift)
5353

5454
target_compile_options(TSCBasic PUBLIC
55-
# Don't use GNU strerror_r on Android.
56-
"$<$<PLATFORM_ID:Android>:SHELL:-Xcc -U_GNU_SOURCE>"
5755
# Ignore secure function warnings on Windows.
5856
"$<$<PLATFORM_ID:Windows>:SHELL:-Xcc -D_CRT_SECURE_NO_WARNINGS>")
5957
target_link_libraries(TSCBasic PRIVATE

Sources/TSCBasic/misc.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
See http://swift.org/CONTRIBUTORS.txt for Swift project authors
99
*/
1010

11+
@_implementationOnly import TSCclibc
1112
import TSCLibc
1213
import Foundation
1314
#if os(Windows)
@@ -327,7 +328,7 @@ extension SystemError: CustomStringConvertible {
327328
var cap = 64
328329
while cap <= 16 * 1024 {
329330
var buf = [Int8](repeating: 0, count: cap)
330-
let err = TSCLibc.strerror_r(errno, &buf, buf.count)
331+
let err = TSCclibc.tsc_strerror_r(errno, &buf, buf.count)
331332
if err == EINVAL {
332333
return "Unknown error \(errno)"
333334
}

Sources/TSCclibc/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors
88

99
add_library(TSCclibc STATIC
10-
libc.c process.c)
10+
libc.c process.c strerror.c)
1111
target_include_directories(TSCclibc PUBLIC
1212
include)
1313
target_compile_definitions(TSCclibc PRIVATE

Sources/TSCclibc/include/module.modulemap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@ module TSCclibc {
22
header "TSCclibc.h"
33
header "indexstore_functions.h"
44
header "process.h"
5+
header "strerror.h"
56
export *
67
}

Sources/TSCclibc/include/strerror.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#include <stddef.h>
2+
3+
#ifndef _WIN32
4+
extern int tsc_strerror_r(int errnum, char *buf, size_t buflen);
5+
#endif

Sources/TSCclibc/strerror.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#undef _GNU_SOURCE
2+
#include "strerror.h"
3+
#include <string.h>
4+
5+
#ifndef _WIN32
6+
int tsc_strerror_r(int errnum, char *buf, size_t buflen) {
7+
return strerror_r(errnum, buf, buflen);
8+
}
9+
#endif

0 commit comments

Comments
 (0)