From 48581139e26d006ae771ca2cec46c81fc4464097 Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Fri, 8 Jul 2022 09:03:52 -0700 Subject: [PATCH] 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. --- Sources/Foundation/NSError.swift | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/Sources/Foundation/NSError.swift b/Sources/Foundation/NSError.swift index d5a8f67a07..516c8cbc8b 100644 --- a/Sources/Foundation/NSError.swift +++ b/Sources/Foundation/NSError.swift @@ -995,14 +995,6 @@ extension POSIXErrorCode: _ErrorCodeProtocol { public typealias _ErrorType = POSIXError } -#if os(Windows) -extension POSIXErrorCode { - public static var ECANCELED: POSIXErrorCode { - return POSIXError.Code(rawValue: WinSDK.ECANCELED)! - } -} -#endif - extension POSIXError { /// Operation not permitted. public static var EPERM: POSIXError.Code { return .EPERM } @@ -1322,7 +1314,13 @@ extension POSIXError { #endif /// Operation canceled. - public static var ECANCELED: POSIXError.Code { return .ECANCELED } + public static var ECANCELED: POSIXError.Code { +#if os(Windows) + return POSIXError.Code(rawValue: ERROR_CANCELLED)! +#else + return .ECANCELED +#endif + } #if !os(Windows) /// Identifier removed.