From c25ca6629bd47ce337c646768e6157324e6094b6 Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Fri, 26 Jul 2024 06:22:13 +0000 Subject: [PATCH] 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. --- .../Error/CocoaError+FilePath.swift | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Sources/FoundationEssentials/Error/CocoaError+FilePath.swift b/Sources/FoundationEssentials/Error/CocoaError+FilePath.swift index fbce0f6f8..f9e108bd0 100644 --- a/Sources/FoundationEssentials/Error/CocoaError+FilePath.swift +++ b/Sources/FoundationEssentials/Error/CocoaError+FilePath.swift @@ -94,7 +94,15 @@ extension CocoaError { var userInfo = userInfo // (130280235) POSIXError.Code does not have a case for EOPNOTSUPP - if errno != EOPNOTSUPP { + let _EOPNOTSUPP: Int32 + #if os(WASI) + // wasi-libc's errno.h constants cannot be directly imported into Swift + // so we use Swift stdlib's POSIXErrorCode instead + _EOPNOTSUPP = POSIXErrorCode.EOPNOTSUPP.rawValue + #else + _EOPNOTSUPP = EOPNOTSUPP + #endif + if errno != _EOPNOTSUPP { guard let code = POSIXError.Code(rawValue: errno) else { fatalError("Invalid posix errno \(errno)") }