Skip to content

Commit 4858113

Browse files
committed
Foundation: rework handling for ECANCELED
Windows does not have a proper POSIX equivalent to `ECANCELED`. The closes equivalent appears to be `WSAECANCELLED` which is a WinSock error code for a cancelled operation. The Windows Error `ERROR_CANCELLED` (0x04c7) is the ideal mapping even though the error code resides in a different domain. As long as the error code is compared via name, this should be safe.
1 parent 18b19a5 commit 4858113

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

Sources/Foundation/NSError.swift

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -995,14 +995,6 @@ extension POSIXErrorCode: _ErrorCodeProtocol {
995995
public typealias _ErrorType = POSIXError
996996
}
997997

998-
#if os(Windows)
999-
extension POSIXErrorCode {
1000-
public static var ECANCELED: POSIXErrorCode {
1001-
return POSIXError.Code(rawValue: WinSDK.ECANCELED)!
1002-
}
1003-
}
1004-
#endif
1005-
1006998
extension POSIXError {
1007999
/// Operation not permitted.
10081000
public static var EPERM: POSIXError.Code { return .EPERM }
@@ -1322,7 +1314,13 @@ extension POSIXError {
13221314
#endif
13231315

13241316
/// Operation canceled.
1325-
public static var ECANCELED: POSIXError.Code { return .ECANCELED }
1317+
public static var ECANCELED: POSIXError.Code {
1318+
#if os(Windows)
1319+
return POSIXError.Code(rawValue: ERROR_CANCELLED)!
1320+
#else
1321+
return .ECANCELED
1322+
#endif
1323+
}
13261324

13271325
#if !os(Windows)
13281326
/// Identifier removed.

0 commit comments

Comments
 (0)