Skip to content

Commit c2718fe

Browse files
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.
1 parent 651e4fb commit c2718fe

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

Sources/Testing/Attachments/Test.Attachment.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ extension Test.Attachment {
246246
file = try FileHandle(atPath: preferredPath, mode: "wxb")
247247
result = preferredPath
248248
break
249-
} catch let error as CError where error.rawValue == EEXIST {
249+
} catch let error as CError where error.rawValue == swt_EEXIST() {
250250
// Try again with a new suffix.
251251
continue
252252
} catch where usingPreferredName {

Sources/_TestingInternals/include/Stubs.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,14 @@ static int swt_siginfo_t_si_status(const siginfo_t *siginfo) {
154154
#endif
155155
#endif
156156

157+
/// Get the value of `EEXIST`.
158+
///
159+
/// This function is provided because `EEXIST` is a complex macro in wasi-libc
160+
/// and cannot be imported directly into Swift.
161+
static int swt_EEXIST(void) {
162+
return EEXIST;
163+
}
164+
157165
SWT_ASSUME_NONNULL_END
158166

159167
#endif

0 commit comments

Comments
 (0)