From ac6ec0b19d6a11dc3afbdb98d26e3635b9c8b6e2 Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Fri, 23 Oct 2020 14:30:15 -0700 Subject: [PATCH] SystemInternals: make WindowsSyscallAdapters build Correct some type errors, missing return type. Add a FIXME comment regarding large file access. --- Sources/SystemInternals/Exports.swift | 6 ++++++ .../SystemInternals/WindowsSyscallAdapters.swift | 13 ++++++++----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/Sources/SystemInternals/Exports.swift b/Sources/SystemInternals/Exports.swift index 5fec904..e03c96f 100644 --- a/Sources/SystemInternals/Exports.swift +++ b/Sources/SystemInternals/Exports.swift @@ -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) diff --git a/Sources/SystemInternals/WindowsSyscallAdapters.swift b/Sources/SystemInternals/WindowsSyscallAdapters.swift index 7a97695..2cc46d2 100644 --- a/Sources/SystemInternals/WindowsSyscallAdapters.swift +++ b/Sources/SystemInternals/WindowsSyscallAdapters.swift @@ -9,8 +9,11 @@ #if os(Windows) +import ucrt +import WinSDK + @inline(__always) -internal func open(_ path: UnsafePointer, _ oflag: Int32) { +internal func open(_ path: UnsafePointer, _ oflag: Int32) -> CInt { var fh: CInt = -1 _ = _sopen_s(&fh, path, oflag, _SH_DENYNO, _S_IREAD | _S_IWRITE) return fh @@ -18,7 +21,7 @@ internal func open(_ path: UnsafePointer, _ oflag: Int32) { @inline(__always) internal func open( - _ path: UnsafePointer, _ oflag: Int32, _ mode: mode_t + _ path: UnsafePointer, _ oflag: Int32, _ mode: CModeT ) -> CInt { // TODO(compnerd): Apply read/write permissions var fh: CInt = -1 @@ -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)