Skip to content

Commit 9532cea

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 9532cea

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

Sources/FoundationEssentials/Error/CocoaError+FilePath.swift

+9-1
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,16 @@ extension CocoaError {
9393
private static func _errorWithErrno(_ errno: Int32, reading: Bool, variant: String?, userInfo: [String : AnyHashable]) -> CocoaError {
9494
var userInfo = userInfo
9595

96+
let _EOPNOTSUPP: Int32
97+
#if canImport(Darwin)
9698
// (130280235) POSIXError.Code does not have a case for EOPNOTSUPP
97-
if errno != EOPNOTSUPP {
99+
_EOPNOTSUPP = EOPNOTSUPP
100+
#else
101+
// wasi-libc's errno.h constants cannot be directly imported into Swift
102+
// so we use Swift stdlib's POSIXErrorCode instead
103+
_EOPNOTSUPP = POSIXErrorCode.EOPNOTSUPP.rawValue
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)