1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
|
#if SYSTEM_PACKAGE_DARWIN
import Darwin
#elseif canImport(Glibc)
import CSystem
import Glibc
#elseif canImport(Musl)
import CSystem
import Musl
#elseif canImport(Android)
import CSystem
import Android
#elseif os(Windows)
import ucrt
import WinSDK
#else
#error("Unsupported Platform")
#endif
import SystemPackage
#if !os(Windows)
// openat
internal func system_openat(
_ fd: Int32,
_ path: UnsafePointer<CInterop.PlatformChar>,
_ oflag: Int32
) -> CInt {
return openat(fd, path, oflag)
}
internal func system_openat(
_ fd: Int32,
_ path: UnsafePointer<CInterop.PlatformChar>,
_ oflag: Int32, _ mode: CInterop.Mode
) -> CInt {
return openat(fd, path, oflag, mode)
}
// fcntl
internal func system_fcntl(_ fd: Int32, _ cmd: Int32, _ value: UnsafeMutableRawPointer) -> CInt {
return fcntl(fd, cmd, value)
}
internal func system_fcntl(_ fd: Int32, _ cmd: Int32, _ value: CInt) -> CInt {
return fcntl(fd, cmd, value)
}
internal func system_fcntl(_ fd: Int32, _ cmd: Int32) -> CInt {
return fcntl(fd, cmd)
}
// fsync
internal func system_fsync(_ fd: Int32) -> CInt {
return fsync(fd)
}
#endif
#if os(Linux) || os(FreeBSD) || os(OpenBSD) || os(Android) || os(Cygwin) || os(PS4)
// fdatasync
internal func system_fdatasync(_ fd: Int32) -> CInt {
return fdatasync(fd)
}
#endif
#if os(Linux) || os(Android)
// posix_fadvise
internal func system_posix_fadvise(
_ fd: Int32, _ offset: Int, _ length: Int, _ advice: CInt
) -> CInt {
return posix_fadvise(fd, .init(offset), .init(length), advice)
}
#endif
// fstat
internal func system_fstat(_ fd: Int32, _ stat: UnsafeMutablePointer<stat>) -> CInt {
return fstat(fd, stat)
}
#if !os(Windows)
// fstatat
internal func system_fstatat(
_ fd: Int32, _ path: UnsafePointer<CInterop.PlatformChar>,
_ stat: UnsafeMutablePointer<stat>,
_ flags: Int32
) -> CInt {
return fstatat(fd, path, stat, flags)
}
// unlinkat
internal func system_unlinkat(
_ fd: Int32, _ path: UnsafePointer<CInterop.PlatformChar>,
_ flags: Int32
) -> CInt {
return unlinkat(fd, path, flags)
}
// ftruncate
internal func system_ftruncate(_ fd: Int32, _ size: off_t) -> CInt {
return ftruncate(fd, size)
}
// mkdirat
internal func system_mkdirat(
_ fd: Int32, _ path: UnsafePointer<CChar>, _ mode: CInterop.Mode
) -> CInt {
return mkdirat(fd, path, mode)
}
// symlinkat
internal func system_symlinkat(
_ oldPath: UnsafePointer<CChar>, _ newDirFd: Int32, _ newPath: UnsafePointer<CChar>
) -> CInt {
return symlinkat(oldPath, newDirFd, newPath)
}
extension CInterop {
#if SYSTEM_PACKAGE_DARWIN
public typealias DirP = UnsafeMutablePointer<DIR>
#elseif os(Linux) || os(Android)
public typealias DirP = OpaquePointer
#else
#error("Unsupported Platform")
#endif
}
// fdopendir
internal func system_fdopendir(_ fd: Int32) -> CInterop.DirP? {
return fdopendir(fd)
}
// readdir
internal func system_readdir(_ dirp: CInterop.DirP) -> UnsafeMutablePointer<dirent>? {
return readdir(dirp)
}
#endif
#if os(Windows)
extension CInterop {
public typealias TimeSpec = FILETIME
}
#else
extension CInterop {
public typealias ClockId = clockid_t
public typealias TimeSpec = timespec
}
// futimens
internal func system_futimens(_ fd: Int32, _ times: UnsafePointer<CInterop.TimeSpec>) -> CInt {
return futimens(fd, times)
}
// clock_gettime
internal func system_clock_gettime(_ id: CInterop.ClockId, _ tp: UnsafeMutablePointer<CInterop.TimeSpec>) -> CInt {
return clock_gettime(id, tp)
}
// clock_getres
internal func system_clock_getres(_ id: CInterop.ClockId, _ tp: UnsafeMutablePointer<CInterop.TimeSpec>) -> CInt {
return clock_getres(id, tp)
}
#endif
|