Skip to content

Commit 0b0d9d5

Browse files
authored
Merge pull request #12 from compnerd/compile
Follow up to #11 to repair the build
2 parents 28916d2 + ac6ec0b commit 0b0d9d5

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

Sources/SystemInternals/Exports.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ import Glibc
2121

2222
public typealias COffT = off_t
2323

24+
#if os(Windows)
25+
public typealias CModeT = CInt
26+
#else
27+
public typealias CModeT = mode_t
28+
#endif
29+
2430
// MARK: syscalls and variables
2531

2632
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)

Sources/SystemInternals/Mocking.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ public class MockingDriver {
8787
import Darwin
8888
#elseif os(Linux) || os(FreeBSD) || os(Android)
8989
import Glibc
90+
#elseif os(Windows)
91+
import ucrt
92+
import WinSDK
9093
#else
9194
#error("Unsupported Platform")
9295
#endif
@@ -95,14 +98,14 @@ import Glibc
9598
#if os(Windows)
9699
internal typealias TLSKey = DWORD
97100
internal func makeTLSKey() -> TLSKey {
98-
var raw: DWORD = FlsAlloc(nil)
101+
let raw: DWORD = FlsAlloc(nil)
99102
if raw == FLS_OUT_OF_INDEXES {
100103
fatalError("Unable to create key")
101104
}
102105
return raw
103106
}
104107
internal func setTLS(_ key: TLSKey, _ p: UnsafeMutableRawPointer?) {
105-
guard 0 != FlsSetValue(key, p) else {
108+
guard FlsSetValue(key, p) else {
106109
fatalError("Unable to set TLS")
107110
}
108111
}

Sources/SystemInternals/WindowsSyscallAdapters.swift

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,19 @@
99

1010
#if os(Windows)
1111

12+
import ucrt
13+
import WinSDK
14+
1215
@inline(__always)
13-
internal func open(_ path: UnsafePointer<CChar>, _ oflag: Int32) {
16+
internal func open(_ path: UnsafePointer<CChar>, _ oflag: Int32) -> CInt {
1417
var fh: CInt = -1
1518
_ = _sopen_s(&fh, path, oflag, _SH_DENYNO, _S_IREAD | _S_IWRITE)
1619
return fh
1720
}
1821

1922
@inline(__always)
2023
internal func open(
21-
_ path: UnsafePointer<CChar>, _ oflag: Int32, _ mode: mode_t
24+
_ path: UnsafePointer<CChar>, _ oflag: Int32, _ mode: CModeT
2225
) -> CInt {
2326
// TODO(compnerd): Apply read/write permissions
2427
var fh: CInt = -1
@@ -33,9 +36,9 @@ internal func close(_ fd: Int32) -> Int32 {
3336

3437
@inline(__always)
3538
internal func lseek(
36-
_ fd: Int32, _ off: off_t, _ whence: Int32
37-
) -> off_t {
38-
_lseek(fd, off, whence)
39+
_ fd: Int32, _ off: Int64, _ whence: Int32
40+
) -> Int64 {
41+
_lseeki64(fd, off, whence)
3942
}
4043

4144
@inline(__always)

0 commit comments

Comments
 (0)