File tree Expand file tree Collapse file tree 1 file changed +28
-1
lines changed Expand file tree Collapse file tree 1 file changed +28
-1
lines changed Original file line number Diff line number Diff line change 7
7
//
8
8
9
9
import Foundation
10
+ import Bluetooth
11
+
12
+ #if canImport(MSVCRT)
13
+ import MSVCRT
14
+ import WinSDK
15
+ #elseif canImport(Darwin)
16
+ import Darwin
17
+ #elseif canImport(Glibc)
18
+ import Glibc
19
+ #endif
10
20
11
21
internal extension POSIXError {
12
22
13
23
/// Creates error from C ```errno```.
14
24
static var fromErrno : POSIXError ? {
15
25
16
- guard let code = POSIXError . Code ( rawValue: POSIXError . Code . RawValue ( errno) )
26
+ guard let code = POSIXErrorCode ( rawValue: errno)
17
27
else { return nil }
18
28
19
29
return self . init ( code)
20
30
}
31
+
32
+ /// Initializes `POSIXError` from an error code.
33
+ init ( _ errorCode: POSIXErrorCode ) {
34
+
35
+ var userInfo = [ String: Any] ( minimumCapacity: 1 )
36
+
37
+ if let description = String ( cString: strerror ( errorCode. rawValue) , encoding: . ascii) {
38
+ userInfo [ NSLocalizedDescriptionKey] = description
39
+ }
40
+
41
+ let nsError = NSError (
42
+ domain: NSPOSIXErrorDomain,
43
+ code: Int ( errorCode. rawValue) ,
44
+ userInfo: userInfo)
45
+
46
+ self . init ( _nsError: nsError)
47
+ }
21
48
}
You can’t perform that action at this time.
0 commit comments