Skip to content

Commit c25ca66

Browse files
Use POSIXErrorCode instead of direct errno E constants from libc
wasi-libc's E constants cannot be imported directly by ClangImporter, so we should use `POSIXErrorCode` from Swift instead.
1 parent b6ca869 commit c25ca66

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

Sources/FoundationEssentials/Error/CocoaError+FilePath.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,15 @@ extension CocoaError {
9494
var userInfo = userInfo
9595

9696
// (130280235) POSIXError.Code does not have a case for EOPNOTSUPP
97-
if errno != EOPNOTSUPP {
97+
let _EOPNOTSUPP: Int32
98+
#if os(WASI)
99+
// wasi-libc's errno.h constants cannot be directly imported into Swift
100+
// so we use Swift stdlib's POSIXErrorCode instead
101+
_EOPNOTSUPP = POSIXErrorCode.EOPNOTSUPP.rawValue
102+
#else
103+
_EOPNOTSUPP = EOPNOTSUPP
104+
#endif
105+
if errno != _EOPNOTSUPP {
98106
guard let code = POSIXError.Code(rawValue: errno) else {
99107
fatalError("Invalid posix errno \(errno)")
100108
}

0 commit comments

Comments
 (0)