From c2718fe9a0191f8889b5aca324ee4c212e382ad3 Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Sun, 3 Nov 2024 05:58:21 +0000 Subject: [PATCH] Access to `EEXIST` through a stub getter function This change introduces a new function `swt_EEXIST` to get the value of `EEXIST` because it is a complex macro in wasi-libc and cannot be imported directly into Swift. --- Sources/Testing/Attachments/Test.Attachment.swift | 2 +- Sources/_TestingInternals/include/Stubs.h | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/Sources/Testing/Attachments/Test.Attachment.swift b/Sources/Testing/Attachments/Test.Attachment.swift index 68fc44ffc..5cdf1dbde 100644 --- a/Sources/Testing/Attachments/Test.Attachment.swift +++ b/Sources/Testing/Attachments/Test.Attachment.swift @@ -246,7 +246,7 @@ extension Test.Attachment { file = try FileHandle(atPath: preferredPath, mode: "wxb") result = preferredPath break - } catch let error as CError where error.rawValue == EEXIST { + } catch let error as CError where error.rawValue == swt_EEXIST() { // Try again with a new suffix. continue } catch where usingPreferredName { diff --git a/Sources/_TestingInternals/include/Stubs.h b/Sources/_TestingInternals/include/Stubs.h index 87b023393..4e114f751 100644 --- a/Sources/_TestingInternals/include/Stubs.h +++ b/Sources/_TestingInternals/include/Stubs.h @@ -154,6 +154,14 @@ static int swt_siginfo_t_si_status(const siginfo_t *siginfo) { #endif #endif +/// Get the value of `EEXIST`. +/// +/// This function is provided because `EEXIST` is a complex macro in wasi-libc +/// and cannot be imported directly into Swift. +static int swt_EEXIST(void) { + return EEXIST; +} + SWT_ASSUME_NONNULL_END #endif