Skip to content

Bring back "Use C to force the POSIX (not GNU) overload of strerror_r to be selected" #500

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions Sources/TSCBasic/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ add_library(TSCBasic
misc.swift)

target_compile_options(TSCBasic PUBLIC
# Don't use GNU strerror_r on Android.
"$<$<PLATFORM_ID:Android>:SHELL:-Xcc -U_GNU_SOURCE>"
# Ignore secure function warnings on Windows.
"$<$<PLATFORM_ID:Windows>:SHELL:-Xcc -D_CRT_SECURE_NO_WARNINGS>")
target_link_libraries(TSCBasic PRIVATE
Expand Down
3 changes: 2 additions & 1 deletion Sources/TSCBasic/misc.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
See http://swift.org/CONTRIBUTORS.txt for Swift project authors
*/

@_implementationOnly import TSCclibc
import TSCLibc
import Foundation
#if os(Windows)
Expand Down Expand Up @@ -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)"
}
Expand Down
3 changes: 2 additions & 1 deletion Sources/TSCclibc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
"$<$<PLATFORM_ID:Linux>:_GNU_SOURCE>")
set_target_properties(TSCclibc PROPERTIES POSITION_INDEPENDENT_CODE YES)

if(NOT BUILD_SHARED_LIBS)
install(TARGETS TSCclibc
Expand Down
1 change: 1 addition & 0 deletions Sources/TSCclibc/include/module.modulemap
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ module TSCclibc {
header "TSCclibc.h"
header "indexstore_functions.h"
header "process.h"
header "strerror.h"
export *
}
5 changes: 5 additions & 0 deletions Sources/TSCclibc/include/strerror.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include <stddef.h>

#ifndef _WIN32
extern int tsc_strerror_r(int errnum, char *buf, size_t buflen);
#endif
9 changes: 9 additions & 0 deletions Sources/TSCclibc/strerror.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#undef _GNU_SOURCE
#include "strerror.h"
#include <string.h>

#ifndef _WIN32
int tsc_strerror_r(int errnum, char *buf, size_t buflen) {
return strerror_r(errnum, buf, buflen);
}
#endif