Skip to content

Commit

Permalink
Merge pull request #12 from compnerd/compile
Browse files Browse the repository at this point in the history
Follow up to #11 to repair the build
  • Loading branch information
milseman authored Oct 25, 2020
2 parents 28916d2 + ac6ec0b commit 0b0d9d5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
6 changes: 6 additions & 0 deletions Sources/SystemInternals/Exports.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ import Glibc

public typealias COffT = off_t

#if os(Windows)
public typealias CModeT = CInt
#else
public typealias CModeT = mode_t
#endif

// MARK: syscalls and variables

#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
Expand Down
7 changes: 5 additions & 2 deletions Sources/SystemInternals/Mocking.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ public class MockingDriver {
import Darwin
#elseif os(Linux) || os(FreeBSD) || os(Android)
import Glibc
#elseif os(Windows)
import ucrt
import WinSDK
#else
#error("Unsupported Platform")
#endif
Expand All @@ -95,14 +98,14 @@ import Glibc
#if os(Windows)
internal typealias TLSKey = DWORD
internal func makeTLSKey() -> TLSKey {
var raw: DWORD = FlsAlloc(nil)
let raw: DWORD = FlsAlloc(nil)
if raw == FLS_OUT_OF_INDEXES {
fatalError("Unable to create key")
}
return raw
}
internal func setTLS(_ key: TLSKey, _ p: UnsafeMutableRawPointer?) {
guard 0 != FlsSetValue(key, p) else {
guard FlsSetValue(key, p) else {
fatalError("Unable to set TLS")
}
}
Expand Down
13 changes: 8 additions & 5 deletions Sources/SystemInternals/WindowsSyscallAdapters.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,19 @@

#if os(Windows)

import ucrt
import WinSDK

@inline(__always)
internal func open(_ path: UnsafePointer<CChar>, _ oflag: Int32) {
internal func open(_ path: UnsafePointer<CChar>, _ oflag: Int32) -> CInt {
var fh: CInt = -1
_ = _sopen_s(&fh, path, oflag, _SH_DENYNO, _S_IREAD | _S_IWRITE)
return fh
}

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

@inline(__always)
internal func lseek(
_ fd: Int32, _ off: off_t, _ whence: Int32
) -> off_t {
_lseek(fd, off, whence)
_ fd: Int32, _ off: Int64, _ whence: Int32
) -> Int64 {
_lseeki64(fd, off, whence)
}

@inline(__always)
Expand Down

0 comments on commit 0b0d9d5

Please sign in to comment.