mirror of
https://github.com/apple/swift-system
synced 2026-11-24 04:38:14 +00:00
Compare commits
24
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d2ba781702 | ||
|
|
a1f77d0e1a | ||
|
|
6a9e38e7bd | ||
|
|
2b30f8820c | ||
|
|
f9d6b48027 | ||
|
|
f9266c8518 | ||
|
|
b7dc8e8e41 | ||
|
|
7d45e0dd46 | ||
|
|
ab09f04cfe | ||
|
|
0cf079efea | ||
|
|
52f603c6b3 | ||
|
|
de1f8bce5e | ||
|
|
0368ce547b | ||
|
|
7b14e48d0d | ||
|
|
c456f4186e | ||
|
|
ec395a7aa2 | ||
|
|
f1f59e148f | ||
|
|
37a5bbb965 | ||
|
|
f07d14ddb1 | ||
|
|
9620c1d30e | ||
|
|
c7259554b5 | ||
|
|
c3a7235bf7 | ||
|
|
e5a56da50e | ||
|
|
dd45c80062 |
No files matched your search
@@ -0,0 +1,13 @@
|
|||||||
|
# Lines starting with '#' are comments.
|
||||||
|
# Each line is a case-sensitive file pattern followed by one or more owners.
|
||||||
|
# Order is important. The last matching pattern has the most precedence.
|
||||||
|
# More information: https://docs.github.com/en/articles/about-code-owners
|
||||||
|
#
|
||||||
|
# Please mirror the repository's file hierarchy in case-sensitive lexicographic
|
||||||
|
# order.
|
||||||
|
|
||||||
|
# Default owners
|
||||||
|
* @glessard @lorentey @milseman
|
||||||
|
|
||||||
|
# Swift CI configuration files
|
||||||
|
.swiftci/ @shahmishal
|
||||||
@@ -4,3 +4,4 @@
|
|||||||
/*.xcodeproj
|
/*.xcodeproj
|
||||||
xcuserdata/
|
xcuserdata/
|
||||||
.*.sw?
|
.*.sw?
|
||||||
|
/.swiftpm
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
LinuxSwiftPackageJob {
|
||||||
|
swift_version_tag = "5.10-jammy"
|
||||||
|
repo = "swift-system"
|
||||||
|
branch = "release/1.3.0"
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
LinuxSwiftPackageJob {
|
||||||
|
swift_version_tag = "5.8-jammy"
|
||||||
|
repo = "swift-system"
|
||||||
|
branch = "release/1.3.0"
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
LinuxSwiftPackageJob {
|
||||||
|
swift_version_tag = "5.9-jammy"
|
||||||
|
repo = "swift-system"
|
||||||
|
branch = "release/1.3.0"
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
macOSSwiftPackageJob {
|
||||||
|
swift_version = "6.0"
|
||||||
|
repo = "swift-system"
|
||||||
|
branch = "release/1.3.0"
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
LinuxSwiftPackageJob {
|
||||||
|
nightly_docker_tag = "nightly-6.0-jammy"
|
||||||
|
repo = "swift-system"
|
||||||
|
branch = "release/1.3.0"
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
macOSSwiftPackageJob {
|
||||||
|
swift_version = "main"
|
||||||
|
repo = "swift-system"
|
||||||
|
branch = "release/1.3.0"
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
LinuxSwiftPackageJob {
|
||||||
|
nightly_docker_tag = "nightly-jammy"
|
||||||
|
repo = "swift-system"
|
||||||
|
branch = "release/1.3.0"
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
WindowsSwiftPackageWithDockerImageJob {
|
||||||
|
docker_image = "swiftlang/swift:nightly-windowsservercore-1809"
|
||||||
|
repo = "swift-system"
|
||||||
|
branch = "release/1.3.0"
|
||||||
|
sub_dir = "swift-system"
|
||||||
|
label = "windows-server-2019"
|
||||||
|
}
|
||||||
+15
-5
@@ -1,10 +1,9 @@
|
|||||||
// swift-tools-version:5.2
|
// swift-tools-version:5.8
|
||||||
// The swift-tools-version declares the minimum version of Swift required to build this package.
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
This source file is part of the Swift System open source project
|
This source file is part of the Swift System open source project
|
||||||
|
|
||||||
Copyright (c) 2020 Apple Inc. and the Swift System project authors
|
Copyright (c) 2020-2024 Apple Inc. and the Swift System project authors
|
||||||
Licensed under Apache License v2.0 with Runtime Library Exception
|
Licensed under Apache License v2.0 with Runtime Library Exception
|
||||||
|
|
||||||
See https://swift.org/LICENSE.txt for license information
|
See https://swift.org/LICENSE.txt for license information
|
||||||
@@ -12,6 +11,13 @@
|
|||||||
|
|
||||||
import PackageDescription
|
import PackageDescription
|
||||||
|
|
||||||
|
let DarwinPlatforms: [Platform]
|
||||||
|
#if swift(<5.9)
|
||||||
|
DarwinPlatforms = [.macOS, .iOS, .watchOS, .tvOS]
|
||||||
|
#else
|
||||||
|
DarwinPlatforms = [.macOS, .iOS, .watchOS, .tvOS, .visionOS]
|
||||||
|
#endif
|
||||||
|
|
||||||
let package = Package(
|
let package = Package(
|
||||||
name: "swift-system",
|
name: "swift-system",
|
||||||
products: [
|
products: [
|
||||||
@@ -21,23 +27,27 @@ let package = Package(
|
|||||||
targets: [
|
targets: [
|
||||||
.target(
|
.target(
|
||||||
name: "CSystem",
|
name: "CSystem",
|
||||||
dependencies: []),
|
dependencies: [],
|
||||||
|
exclude: ["CMakeLists.txt"]),
|
||||||
.target(
|
.target(
|
||||||
name: "SystemPackage",
|
name: "SystemPackage",
|
||||||
dependencies: ["CSystem"],
|
dependencies: ["CSystem"],
|
||||||
path: "Sources/System",
|
path: "Sources/System",
|
||||||
|
exclude: ["CMakeLists.txt"],
|
||||||
cSettings: [
|
cSettings: [
|
||||||
.define("_CRT_SECURE_NO_WARNINGS")
|
.define("_CRT_SECURE_NO_WARNINGS")
|
||||||
],
|
],
|
||||||
swiftSettings: [
|
swiftSettings: [
|
||||||
.define("SYSTEM_PACKAGE"),
|
.define("SYSTEM_PACKAGE"),
|
||||||
|
.define("SYSTEM_PACKAGE_DARWIN", .when(platforms: DarwinPlatforms)),
|
||||||
.define("ENABLE_MOCKING", .when(configuration: .debug))
|
.define("ENABLE_MOCKING", .when(configuration: .debug))
|
||||||
]),
|
]),
|
||||||
.testTarget(
|
.testTarget(
|
||||||
name: "SystemTests",
|
name: "SystemTests",
|
||||||
dependencies: ["SystemPackage"],
|
dependencies: ["SystemPackage"],
|
||||||
swiftSettings: [
|
swiftSettings: [
|
||||||
.define("SYSTEM_PACKAGE")
|
.define("SYSTEM_PACKAGE"),
|
||||||
|
.define("SYSTEM_PACKAGE_DARWIN", .when(platforms: DarwinPlatforms)),
|
||||||
]),
|
]),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
@@ -28,7 +28,7 @@ To use the `SystemPackage` library in a SwiftPM project,
|
|||||||
add the following line to the dependencies in your `Package.swift` file:
|
add the following line to the dependencies in your `Package.swift` file:
|
||||||
|
|
||||||
```swift
|
```swift
|
||||||
.package(url: "https://github.com/apple/swift-system", from: "1.0.0"),
|
.package(url: "https://github.com/apple/swift-system", from: "1.3.0"),
|
||||||
```
|
```
|
||||||
|
|
||||||
Finally, include `"SystemPackage"` as a dependency for your executable target:
|
Finally, include `"SystemPackage"` as a dependency for your executable target:
|
||||||
@@ -37,7 +37,7 @@ Finally, include `"SystemPackage"` as a dependency for your executable target:
|
|||||||
let package = Package(
|
let package = Package(
|
||||||
// name, platforms, products, etc.
|
// name, platforms, products, etc.
|
||||||
dependencies: [
|
dependencies: [
|
||||||
.package(url: "https://github.com/apple/swift-system", from: "1.0.0"),
|
.package(url: "https://github.com/apple/swift-system", from: "1.3.0"),
|
||||||
// other dependencies
|
// other dependencies
|
||||||
],
|
],
|
||||||
targets: [
|
targets: [
|
||||||
|
|||||||
@@ -37,6 +37,10 @@ target_sources(SystemPackage PRIVATE
|
|||||||
target_link_libraries(SystemPackage PUBLIC
|
target_link_libraries(SystemPackage PUBLIC
|
||||||
CSystem)
|
CSystem)
|
||||||
|
|
||||||
|
set(SWIFT_SYSTEM_APPLE_PLATFORMS "Darwin" "iOS" "watchOS" "tvOS" "visionOS")
|
||||||
|
if(CMAKE_SYSTEM_NAME IN_LIST SWIFT_SYSTEM_APPLE_PLATFORMS)
|
||||||
|
target_compile_definitions(SystemPackage PRIVATE SYSTEM_PACKAGE_DARWIN)
|
||||||
|
endif()
|
||||||
|
|
||||||
_install_target(SystemPackage)
|
_install_target(SystemPackage)
|
||||||
set_property(GLOBAL APPEND PROPERTY SWIFT_SYSTEM_EXPORTS SystemPackage)
|
set_property(GLOBAL APPEND PROPERTY SWIFT_SYSTEM_EXPORTS SystemPackage)
|
||||||
+10
-10
@@ -23,7 +23,7 @@ public struct Errno: RawRepresentable, Error, Hashable, Codable {
|
|||||||
@_alwaysEmitIntoClient
|
@_alwaysEmitIntoClient
|
||||||
private init(_ raw: CInt) { self.init(rawValue: raw) }
|
private init(_ raw: CInt) { self.init(rawValue: raw) }
|
||||||
|
|
||||||
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
|
#if SYSTEM_PACKAGE_DARWIN
|
||||||
/// Error. Not used.
|
/// Error. Not used.
|
||||||
@_alwaysEmitIntoClient
|
@_alwaysEmitIntoClient
|
||||||
public static var notUsed: Errno { Errno(_ERRNO_NOT_USED) }
|
public static var notUsed: Errno { Errno(_ERRNO_NOT_USED) }
|
||||||
@@ -911,7 +911,7 @@ public struct Errno: RawRepresentable, Error, Hashable, Codable {
|
|||||||
@available(*, unavailable, renamed: "directoryNotEmpty")
|
@available(*, unavailable, renamed: "directoryNotEmpty")
|
||||||
public static var ENOTEMPTY: Errno { directoryNotEmpty }
|
public static var ENOTEMPTY: Errno { directoryNotEmpty }
|
||||||
|
|
||||||
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
|
#if SYSTEM_PACKAGE_DARWIN
|
||||||
/// Too many processes.
|
/// Too many processes.
|
||||||
///
|
///
|
||||||
/// The corresponding C error is `EPROCLIM`.
|
/// The corresponding C error is `EPROCLIM`.
|
||||||
@@ -968,7 +968,7 @@ public struct Errno: RawRepresentable, Error, Hashable, Codable {
|
|||||||
public static var ESTALE: Errno { staleNFSFileHandle }
|
public static var ESTALE: Errno { staleNFSFileHandle }
|
||||||
|
|
||||||
// TODO: Add Linux's RPC equivalents
|
// TODO: Add Linux's RPC equivalents
|
||||||
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
|
#if SYSTEM_PACKAGE_DARWIN
|
||||||
|
|
||||||
/// The structure of the remote procedure call (RPC) is bad.
|
/// The structure of the remote procedure call (RPC) is bad.
|
||||||
///
|
///
|
||||||
@@ -1060,7 +1060,7 @@ public struct Errno: RawRepresentable, Error, Hashable, Codable {
|
|||||||
public static var ENOSYS: Errno { noFunction }
|
public static var ENOSYS: Errno { noFunction }
|
||||||
|
|
||||||
// BSD
|
// BSD
|
||||||
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
|
#if SYSTEM_PACKAGE_DARWIN
|
||||||
/// Inappropriate file type or format.
|
/// Inappropriate file type or format.
|
||||||
///
|
///
|
||||||
/// The file was the wrong type for the operation,
|
/// The file was the wrong type for the operation,
|
||||||
@@ -1075,7 +1075,7 @@ public struct Errno: RawRepresentable, Error, Hashable, Codable {
|
|||||||
public static var EFTYPE: Errno { badFileTypeOrFormat }
|
public static var EFTYPE: Errno { badFileTypeOrFormat }
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
|
#if SYSTEM_PACKAGE_DARWIN
|
||||||
/// Authentication error.
|
/// Authentication error.
|
||||||
///
|
///
|
||||||
/// The authentication ticket used to mount an NFS file system was invalid.
|
/// The authentication ticket used to mount an NFS file system was invalid.
|
||||||
@@ -1102,7 +1102,7 @@ public struct Errno: RawRepresentable, Error, Hashable, Codable {
|
|||||||
public static var ENEEDAUTH: Errno { needAuthenticator }
|
public static var ENEEDAUTH: Errno { needAuthenticator }
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
|
#if SYSTEM_PACKAGE_DARWIN
|
||||||
/// Device power is off.
|
/// Device power is off.
|
||||||
///
|
///
|
||||||
/// The corresponding C error is `EPWROFF`.
|
/// The corresponding C error is `EPWROFF`.
|
||||||
@@ -1142,7 +1142,7 @@ public struct Errno: RawRepresentable, Error, Hashable, Codable {
|
|||||||
public static var EOVERFLOW: Errno { overflow }
|
public static var EOVERFLOW: Errno { overflow }
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
|
#if SYSTEM_PACKAGE_DARWIN
|
||||||
/// Bad executable or shared library.
|
/// Bad executable or shared library.
|
||||||
///
|
///
|
||||||
/// The executable or shared library being referenced was malformed.
|
/// The executable or shared library being referenced was malformed.
|
||||||
@@ -1246,7 +1246,7 @@ public struct Errno: RawRepresentable, Error, Hashable, Codable {
|
|||||||
@available(*, unavailable, renamed: "illegalByteSequence")
|
@available(*, unavailable, renamed: "illegalByteSequence")
|
||||||
public static var EILSEQ: Errno { illegalByteSequence }
|
public static var EILSEQ: Errno { illegalByteSequence }
|
||||||
|
|
||||||
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
|
#if SYSTEM_PACKAGE_DARWIN
|
||||||
/// Attribute not found.
|
/// Attribute not found.
|
||||||
///
|
///
|
||||||
/// The specified extended attribute doesn't exist.
|
/// The specified extended attribute doesn't exist.
|
||||||
@@ -1409,7 +1409,7 @@ extension Errno {
|
|||||||
@available(*, unavailable, renamed: "tooManyRemoteLevels")
|
@available(*, unavailable, renamed: "tooManyRemoteLevels")
|
||||||
public static var EREMOTE: Errno { tooManyRemoteLevels }
|
public static var EREMOTE: Errno { tooManyRemoteLevels }
|
||||||
|
|
||||||
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
|
#if SYSTEM_PACKAGE_DARWIN
|
||||||
/// No such policy registered.
|
/// No such policy registered.
|
||||||
///
|
///
|
||||||
/// The corresponding C error is `ENOPOLICY`.
|
/// The corresponding C error is `ENOPOLICY`.
|
||||||
@@ -1443,7 +1443,7 @@ extension Errno {
|
|||||||
public static var EOWNERDEAD: Errno { previousOwnerDied }
|
public static var EOWNERDEAD: Errno { previousOwnerDied }
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
|
#if SYSTEM_PACKAGE_DARWIN
|
||||||
/// Interface output queue is full.
|
/// Interface output queue is full.
|
||||||
///
|
///
|
||||||
/// The corresponding C error is `EQFULL`.
|
/// The corresponding C error is `EQFULL`.
|
||||||
|
|||||||
@@ -182,7 +182,7 @@ extension FileDescriptor {
|
|||||||
@available(*, unavailable, renamed: "exclusiveCreate")
|
@available(*, unavailable, renamed: "exclusiveCreate")
|
||||||
public static var O_EXCL: OpenOptions { exclusiveCreate }
|
public static var O_EXCL: OpenOptions { exclusiveCreate }
|
||||||
|
|
||||||
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
|
#if SYSTEM_PACKAGE_DARWIN
|
||||||
/// Indicates that opening the file
|
/// Indicates that opening the file
|
||||||
/// atomically obtains a shared lock on the file.
|
/// atomically obtains a shared lock on the file.
|
||||||
///
|
///
|
||||||
@@ -250,7 +250,7 @@ extension FileDescriptor {
|
|||||||
public static var O_DIRECTORY: OpenOptions { directory }
|
public static var O_DIRECTORY: OpenOptions { directory }
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
|
#if SYSTEM_PACKAGE_DARWIN
|
||||||
/// Indicates that opening the file
|
/// Indicates that opening the file
|
||||||
/// opens symbolic links instead of following them.
|
/// opens symbolic links instead of following them.
|
||||||
///
|
///
|
||||||
@@ -353,7 +353,7 @@ extension FileDescriptor {
|
|||||||
|
|
||||||
// TODO: These are available on some versions of Linux with appropriate
|
// TODO: These are available on some versions of Linux with appropriate
|
||||||
// macro defines.
|
// macro defines.
|
||||||
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
|
#if SYSTEM_PACKAGE_DARWIN
|
||||||
/// Indicates that the offset should be set
|
/// Indicates that the offset should be set
|
||||||
/// to the next hole after the specified number of bytes.
|
/// to the next hole after the specified number of bytes.
|
||||||
///
|
///
|
||||||
@@ -415,7 +415,7 @@ extension FileDescriptor.SeekOrigin
|
|||||||
case .start: return "start"
|
case .start: return "start"
|
||||||
case .current: return "current"
|
case .current: return "current"
|
||||||
case .end: return "end"
|
case .end: return "end"
|
||||||
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
|
#if SYSTEM_PACKAGE_DARWIN
|
||||||
case .nextHole: return "nextHole"
|
case .nextHole: return "nextHole"
|
||||||
case .nextData: return "nextData"
|
case .nextData: return "nextData"
|
||||||
#endif
|
#endif
|
||||||
@@ -434,7 +434,7 @@ extension FileDescriptor.OpenOptions
|
|||||||
/// A textual representation of the open options.
|
/// A textual representation of the open options.
|
||||||
@inline(never)
|
@inline(never)
|
||||||
public var description: String {
|
public var description: String {
|
||||||
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
|
#if SYSTEM_PACKAGE_DARWIN
|
||||||
let descriptions: [(Element, StaticString)] = [
|
let descriptions: [(Element, StaticString)] = [
|
||||||
(.nonBlocking, ".nonBlocking"),
|
(.nonBlocking, ".nonBlocking"),
|
||||||
(.append, ".append"),
|
(.append, ".append"),
|
||||||
|
|||||||
@@ -67,5 +67,22 @@ extension FilePath {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*System 0.0.1, @available(macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0, *)*/
|
/*System 0.0.1, @available(macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0, *)*/
|
||||||
extension FilePath: Hashable, Codable {}
|
extension FilePath: Hashable, Codable {
|
||||||
|
// Encoder is synthesized; it probably should have been explicit and used
|
||||||
|
// a single-value container, but making that change now is somewhat risky.
|
||||||
|
|
||||||
|
// Decoder is written explicitly to ensure that we validate invariants on
|
||||||
|
// untrusted input.
|
||||||
|
public init(from decoder: any Decoder) throws {
|
||||||
|
let container = try decoder.container(keyedBy: CodingKeys.self)
|
||||||
|
self._storage = try container.decode(SystemString.self, forKey: ._storage)
|
||||||
|
guard _invariantsSatisfied() else {
|
||||||
|
throw DecodingError.dataCorruptedError(
|
||||||
|
forKey: ._storage,
|
||||||
|
in: container,
|
||||||
|
debugDescription:
|
||||||
|
"Encoding does not satisfy the invariants of FilePath"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -359,13 +359,18 @@ extension FilePath {
|
|||||||
|
|
||||||
// MARK: - Invariants
|
// MARK: - Invariants
|
||||||
extension FilePath {
|
extension FilePath {
|
||||||
internal func _invariantCheck() {
|
internal func _invariantsSatisfied() -> Bool {
|
||||||
#if DEBUG
|
|
||||||
var normal = self
|
var normal = self
|
||||||
normal._normalizeSeparators()
|
normal._normalizeSeparators()
|
||||||
precondition(self == normal)
|
guard self == normal else { return false }
|
||||||
precondition(!self._storage._hasTrailingSeparator())
|
guard !self._storage._hasTrailingSeparator() else { return false }
|
||||||
precondition(_hasRoot == (self.root != nil))
|
guard _hasRoot == (self.root != nil) else { return false }
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
internal func _invariantCheck() {
|
||||||
|
#if DEBUG
|
||||||
|
precondition(_invariantsSatisfied())
|
||||||
#endif // DEBUG
|
#endif // DEBUG
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -14,14 +14,17 @@
|
|||||||
@available(*, deprecated, renamed: "CInterop.Mode")
|
@available(*, deprecated, renamed: "CInterop.Mode")
|
||||||
public typealias CModeT = CInterop.Mode
|
public typealias CModeT = CInterop.Mode
|
||||||
|
|
||||||
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
|
#if SYSTEM_PACKAGE_DARWIN
|
||||||
import Darwin
|
import Darwin
|
||||||
#elseif os(Linux) || os(FreeBSD) || os(Android)
|
|
||||||
@_implementationOnly import CSystem
|
|
||||||
import Glibc
|
|
||||||
#elseif os(Windows)
|
#elseif os(Windows)
|
||||||
import CSystem
|
import CSystem
|
||||||
import ucrt
|
import ucrt
|
||||||
|
#elseif canImport(Glibc)
|
||||||
|
@_implementationOnly import CSystem
|
||||||
|
import Glibc
|
||||||
|
#elseif canImport(Musl)
|
||||||
|
@_implementationOnly import CSystem
|
||||||
|
import Musl
|
||||||
#else
|
#else
|
||||||
#error("Unsupported Platform")
|
#error("Unsupported Platform")
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -11,19 +11,22 @@
|
|||||||
// they can be used anywhere without imports and without confusion to
|
// they can be used anywhere without imports and without confusion to
|
||||||
// unavailable local decls.
|
// unavailable local decls.
|
||||||
|
|
||||||
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
|
#if SYSTEM_PACKAGE_DARWIN
|
||||||
import Darwin
|
import Darwin
|
||||||
#elseif os(Linux) || os(FreeBSD) || os(Android)
|
|
||||||
import Glibc
|
|
||||||
#elseif os(Windows)
|
#elseif os(Windows)
|
||||||
import CSystem
|
import CSystem
|
||||||
import ucrt
|
import ucrt
|
||||||
|
#elseif canImport(Glibc)
|
||||||
|
import Glibc
|
||||||
|
#elseif canImport(Musl)
|
||||||
|
import CSystem
|
||||||
|
import Musl
|
||||||
#else
|
#else
|
||||||
#error("Unsupported Platform")
|
#error("Unsupported Platform")
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// MARK: errno
|
// MARK: errno
|
||||||
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
|
#if SYSTEM_PACKAGE_DARWIN
|
||||||
@_alwaysEmitIntoClient
|
@_alwaysEmitIntoClient
|
||||||
internal var _ERRNO_NOT_USED: CInt { 0 }
|
internal var _ERRNO_NOT_USED: CInt { 0 }
|
||||||
#endif
|
#endif
|
||||||
@@ -269,7 +272,7 @@ internal var _EHOSTUNREACH: CInt { EHOSTUNREACH }
|
|||||||
@_alwaysEmitIntoClient
|
@_alwaysEmitIntoClient
|
||||||
internal var _ENOTEMPTY: CInt { ENOTEMPTY }
|
internal var _ENOTEMPTY: CInt { ENOTEMPTY }
|
||||||
|
|
||||||
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
|
#if SYSTEM_PACKAGE_DARWIN
|
||||||
@_alwaysEmitIntoClient
|
@_alwaysEmitIntoClient
|
||||||
internal var _EPROCLIM: CInt { EPROCLIM }
|
internal var _EPROCLIM: CInt { EPROCLIM }
|
||||||
#endif
|
#endif
|
||||||
@@ -310,7 +313,7 @@ internal var _EREMOTE: CInt {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
|
#if SYSTEM_PACKAGE_DARWIN
|
||||||
@_alwaysEmitIntoClient
|
@_alwaysEmitIntoClient
|
||||||
internal var _EBADRPC: CInt { EBADRPC }
|
internal var _EBADRPC: CInt { EBADRPC }
|
||||||
|
|
||||||
@@ -333,7 +336,7 @@ internal var _ENOLCK: CInt { ENOLCK }
|
|||||||
@_alwaysEmitIntoClient
|
@_alwaysEmitIntoClient
|
||||||
internal var _ENOSYS: CInt { ENOSYS }
|
internal var _ENOSYS: CInt { ENOSYS }
|
||||||
|
|
||||||
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
|
#if SYSTEM_PACKAGE_DARWIN
|
||||||
@_alwaysEmitIntoClient
|
@_alwaysEmitIntoClient
|
||||||
internal var _EFTYPE: CInt { EFTYPE }
|
internal var _EFTYPE: CInt { EFTYPE }
|
||||||
|
|
||||||
@@ -355,7 +358,7 @@ internal var _EDEVERR: CInt { EDEVERR }
|
|||||||
internal var _EOVERFLOW: CInt { EOVERFLOW }
|
internal var _EOVERFLOW: CInt { EOVERFLOW }
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
|
#if SYSTEM_PACKAGE_DARWIN
|
||||||
@_alwaysEmitIntoClient
|
@_alwaysEmitIntoClient
|
||||||
internal var _EBADEXEC: CInt { EBADEXEC }
|
internal var _EBADEXEC: CInt { EBADEXEC }
|
||||||
|
|
||||||
@@ -383,7 +386,7 @@ internal var _ENOMSG: CInt { ENOMSG }
|
|||||||
@_alwaysEmitIntoClient
|
@_alwaysEmitIntoClient
|
||||||
internal var _EILSEQ: CInt { EILSEQ }
|
internal var _EILSEQ: CInt { EILSEQ }
|
||||||
|
|
||||||
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
|
#if SYSTEM_PACKAGE_DARWIN
|
||||||
@_alwaysEmitIntoClient
|
@_alwaysEmitIntoClient
|
||||||
internal var _ENOATTR: CInt { ENOATTR }
|
internal var _ENOATTR: CInt { ENOATTR }
|
||||||
#endif
|
#endif
|
||||||
@@ -417,7 +420,7 @@ internal var _ETIME: CInt { ETIME }
|
|||||||
@_alwaysEmitIntoClient
|
@_alwaysEmitIntoClient
|
||||||
internal var _EOPNOTSUPP: CInt { EOPNOTSUPP }
|
internal var _EOPNOTSUPP: CInt { EOPNOTSUPP }
|
||||||
|
|
||||||
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
|
#if SYSTEM_PACKAGE_DARWIN
|
||||||
@_alwaysEmitIntoClient
|
@_alwaysEmitIntoClient
|
||||||
internal var _ENOPOLICY: CInt { ENOPOLICY }
|
internal var _ENOPOLICY: CInt { ENOPOLICY }
|
||||||
#endif
|
#endif
|
||||||
@@ -430,7 +433,7 @@ internal var _ENOTRECOVERABLE: CInt { ENOTRECOVERABLE }
|
|||||||
internal var _EOWNERDEAD: CInt { EOWNERDEAD }
|
internal var _EOWNERDEAD: CInt { EOWNERDEAD }
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
|
#if SYSTEM_PACKAGE_DARWIN
|
||||||
@_alwaysEmitIntoClient
|
@_alwaysEmitIntoClient
|
||||||
internal var _EQFULL: CInt { EQFULL }
|
internal var _EQFULL: CInt { EQFULL }
|
||||||
|
|
||||||
@@ -450,9 +453,13 @@ internal var _O_WRONLY: CInt { O_WRONLY }
|
|||||||
internal var _O_RDWR: CInt { O_RDWR }
|
internal var _O_RDWR: CInt { O_RDWR }
|
||||||
|
|
||||||
#if !os(Windows)
|
#if !os(Windows)
|
||||||
|
#if canImport(Musl)
|
||||||
|
internal var _O_ACCMODE: CInt { 0x03|O_SEARCH }
|
||||||
|
#else
|
||||||
// TODO: API?
|
// TODO: API?
|
||||||
@_alwaysEmitIntoClient
|
@_alwaysEmitIntoClient
|
||||||
internal var _O_ACCMODE: CInt { O_ACCMODE }
|
internal var _O_ACCMODE: CInt { O_ACCMODE }
|
||||||
|
#endif
|
||||||
|
|
||||||
@_alwaysEmitIntoClient
|
@_alwaysEmitIntoClient
|
||||||
internal var _O_NONBLOCK: CInt { O_NONBLOCK }
|
internal var _O_NONBLOCK: CInt { O_NONBLOCK }
|
||||||
@@ -461,7 +468,7 @@ internal var _O_NONBLOCK: CInt { O_NONBLOCK }
|
|||||||
@_alwaysEmitIntoClient
|
@_alwaysEmitIntoClient
|
||||||
internal var _O_APPEND: CInt { O_APPEND }
|
internal var _O_APPEND: CInt { O_APPEND }
|
||||||
|
|
||||||
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
|
#if SYSTEM_PACKAGE_DARWIN
|
||||||
@_alwaysEmitIntoClient
|
@_alwaysEmitIntoClient
|
||||||
internal var _O_SHLOCK: CInt { O_SHLOCK }
|
internal var _O_SHLOCK: CInt { O_SHLOCK }
|
||||||
|
|
||||||
@@ -487,7 +494,7 @@ internal var _O_TRUNC: CInt { O_TRUNC }
|
|||||||
@_alwaysEmitIntoClient
|
@_alwaysEmitIntoClient
|
||||||
internal var _O_EXCL: CInt { O_EXCL }
|
internal var _O_EXCL: CInt { O_EXCL }
|
||||||
|
|
||||||
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
|
#if SYSTEM_PACKAGE_DARWIN
|
||||||
@_alwaysEmitIntoClient
|
@_alwaysEmitIntoClient
|
||||||
internal var _O_EVTONLY: CInt { O_EVTONLY }
|
internal var _O_EVTONLY: CInt { O_EVTONLY }
|
||||||
#endif
|
#endif
|
||||||
@@ -501,7 +508,7 @@ internal var _O_NOCTTY: CInt { O_NOCTTY }
|
|||||||
internal var _O_DIRECTORY: CInt { O_DIRECTORY }
|
internal var _O_DIRECTORY: CInt { O_DIRECTORY }
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
|
#if SYSTEM_PACKAGE_DARWIN
|
||||||
@_alwaysEmitIntoClient
|
@_alwaysEmitIntoClient
|
||||||
internal var _O_SYMLINK: CInt { O_SYMLINK }
|
internal var _O_SYMLINK: CInt { O_SYMLINK }
|
||||||
#endif
|
#endif
|
||||||
@@ -520,7 +527,7 @@ internal var _SEEK_CUR: CInt { SEEK_CUR }
|
|||||||
@_alwaysEmitIntoClient
|
@_alwaysEmitIntoClient
|
||||||
internal var _SEEK_END: CInt { SEEK_END }
|
internal var _SEEK_END: CInt { SEEK_END }
|
||||||
|
|
||||||
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
|
#if SYSTEM_PACKAGE_DARWIN
|
||||||
@_alwaysEmitIntoClient
|
@_alwaysEmitIntoClient
|
||||||
internal var _SEEK_HOLE: CInt { SEEK_HOLE }
|
internal var _SEEK_HOLE: CInt { SEEK_HOLE }
|
||||||
|
|
||||||
|
|||||||
@@ -12,14 +12,17 @@
|
|||||||
|
|
||||||
// TODO: Should CSystem just include all the header files we need?
|
// TODO: Should CSystem just include all the header files we need?
|
||||||
|
|
||||||
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
|
#if SYSTEM_PACKAGE_DARWIN
|
||||||
import Darwin
|
import Darwin
|
||||||
#elseif os(Linux) || os(FreeBSD) || os(Android)
|
|
||||||
@_implementationOnly import CSystem
|
|
||||||
import Glibc
|
|
||||||
#elseif os(Windows)
|
#elseif os(Windows)
|
||||||
import CSystem
|
import CSystem
|
||||||
import ucrt
|
import ucrt
|
||||||
|
#elseif canImport(Glibc)
|
||||||
|
@_implementationOnly import CSystem
|
||||||
|
import Glibc
|
||||||
|
#elseif canImport(Musl)
|
||||||
|
@_implementationOnly import CSystem
|
||||||
|
import Musl
|
||||||
#else
|
#else
|
||||||
#error("Unsupported Platform")
|
#error("Unsupported Platform")
|
||||||
#endif
|
#endif
|
||||||
@@ -28,7 +31,7 @@ internal typealias _COffT = off_t
|
|||||||
|
|
||||||
// MARK: syscalls and variables
|
// MARK: syscalls and variables
|
||||||
|
|
||||||
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
|
#if SYSTEM_PACKAGE_DARWIN
|
||||||
internal var system_errno: CInt {
|
internal var system_errno: CInt {
|
||||||
get { Darwin.errno }
|
get { Darwin.errno }
|
||||||
set { Darwin.errno = newValue }
|
set { Darwin.errno = newValue }
|
||||||
@@ -45,11 +48,16 @@ internal var system_errno: CInt {
|
|||||||
_ = ucrt._set_errno(newValue)
|
_ = ucrt._set_errno(newValue)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#else
|
#elseif canImport(Glibc)
|
||||||
internal var system_errno: CInt {
|
internal var system_errno: CInt {
|
||||||
get { Glibc.errno }
|
get { Glibc.errno }
|
||||||
set { Glibc.errno = newValue }
|
set { Glibc.errno = newValue }
|
||||||
}
|
}
|
||||||
|
#elseif canImport(Musl)
|
||||||
|
internal var system_errno: CInt {
|
||||||
|
get { Musl.errno }
|
||||||
|
set { Musl.errno = newValue }
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// MARK: C stdlib decls
|
// MARK: C stdlib decls
|
||||||
|
|||||||
@@ -7,10 +7,12 @@
|
|||||||
See https://swift.org/LICENSE.txt for license information
|
See https://swift.org/LICENSE.txt for license information
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
|
#if SYSTEM_PACKAGE_DARWIN
|
||||||
import Darwin
|
import Darwin
|
||||||
#elseif os(Linux) || os(FreeBSD) || os(Android)
|
#elseif canImport(Glibc)
|
||||||
import Glibc
|
import Glibc
|
||||||
|
#elseif canImport(Musl)
|
||||||
|
import Musl
|
||||||
#elseif os(Windows)
|
#elseif os(Windows)
|
||||||
import ucrt
|
import ucrt
|
||||||
#else
|
#else
|
||||||
@@ -69,7 +71,15 @@ internal func system_pread(
|
|||||||
#if ENABLE_MOCKING
|
#if ENABLE_MOCKING
|
||||||
if mockingEnabled { return _mockInt(fd, buf, nbyte, offset) }
|
if mockingEnabled { return _mockInt(fd, buf, nbyte, offset) }
|
||||||
#endif
|
#endif
|
||||||
|
#if os(Android)
|
||||||
|
var zero = UInt8.zero
|
||||||
|
return withUnsafeMutablePointer(to: &zero) {
|
||||||
|
// this pread has a non-nullable `buf` pointer
|
||||||
|
pread(fd, buf ?? UnsafeMutableRawPointer($0), nbyte, offset)
|
||||||
|
}
|
||||||
|
#else
|
||||||
return pread(fd, buf, nbyte, offset)
|
return pread(fd, buf, nbyte, offset)
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// lseek
|
// lseek
|
||||||
@@ -99,7 +109,15 @@ internal func system_pwrite(
|
|||||||
#if ENABLE_MOCKING
|
#if ENABLE_MOCKING
|
||||||
if mockingEnabled { return _mockInt(fd, buf, nbyte, offset) }
|
if mockingEnabled { return _mockInt(fd, buf, nbyte, offset) }
|
||||||
#endif
|
#endif
|
||||||
|
#if os(Android)
|
||||||
|
var zero = UInt8.zero
|
||||||
|
return withUnsafeMutablePointer(to: &zero) {
|
||||||
|
// this pwrite has a non-nullable `buf` pointer
|
||||||
|
pwrite(fd, buf ?? UnsafeRawPointer($0), nbyte, offset)
|
||||||
|
}
|
||||||
|
#else
|
||||||
return pwrite(fd, buf, nbyte, offset)
|
return pwrite(fd, buf, nbyte, offset)
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
internal func system_dup(_ fd: Int32) -> Int32 {
|
internal func system_dup(_ fd: Int32) -> Int32 {
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ extension String {
|
|||||||
/// This means that, depending on the semantics of the specific platform,
|
/// This means that, depending on the semantics of the specific platform,
|
||||||
/// conversion to a string and back might result in a value that's different
|
/// conversion to a string and back might result in a value that's different
|
||||||
/// from the original platform string.
|
/// from the original platform string.
|
||||||
|
@_disfavoredOverload
|
||||||
public init(platformString: UnsafePointer<CInterop.PlatformChar>) {
|
public init(platformString: UnsafePointer<CInterop.PlatformChar>) {
|
||||||
self.init(_errorCorrectingPlatformString: platformString)
|
self.init(_errorCorrectingPlatformString: platformString)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -95,10 +95,18 @@ extension SystemString {
|
|||||||
}
|
}
|
||||||
|
|
||||||
extension SystemString {
|
extension SystemString {
|
||||||
|
fileprivate func _invariantsSatisfied() -> Bool {
|
||||||
|
guard !nullTerminatedStorage.isEmpty else { return false }
|
||||||
|
guard nullTerminatedStorage.last! == .null else { return false }
|
||||||
|
guard nullTerminatedStorage.firstIndex(of: .null) == length else {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
fileprivate func _invariantCheck() {
|
fileprivate func _invariantCheck() {
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
precondition(nullTerminatedStorage.last! == .null)
|
precondition(_invariantsSatisfied())
|
||||||
precondition(nullTerminatedStorage.firstIndex(of: .null) == length)
|
|
||||||
#endif // DEBUG
|
#endif // DEBUG
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -141,31 +149,58 @@ extension SystemString: RangeReplaceableCollection {
|
|||||||
nullTerminatedStorage.reserveCapacity(1 + n)
|
nullTerminatedStorage.reserveCapacity(1 + n)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Below include null terminator, is this desired?
|
|
||||||
|
|
||||||
internal func withContiguousStorageIfAvailable<R>(
|
internal func withContiguousStorageIfAvailable<R>(
|
||||||
_ body: (UnsafeBufferPointer<SystemChar>) throws -> R
|
_ body: (UnsafeBufferPointer<SystemChar>) throws -> R
|
||||||
) rethrows -> R? {
|
) rethrows -> R? {
|
||||||
try nullTerminatedStorage.withContiguousStorageIfAvailable(body)
|
// Do not include the null terminator, it is outside the Collection
|
||||||
|
try nullTerminatedStorage.withContiguousStorageIfAvailable {
|
||||||
|
try body(.init(start: $0.baseAddress, count: $0.count-1))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal mutating func withContiguousMutableStorageIfAvailable<R>(
|
internal mutating func withContiguousMutableStorageIfAvailable<R>(
|
||||||
_ body: (inout UnsafeMutableBufferPointer<SystemChar>) throws -> R
|
_ body: (inout UnsafeMutableBufferPointer<SystemChar>) throws -> R
|
||||||
) rethrows -> R? {
|
) rethrows -> R? {
|
||||||
defer { _invariantCheck() }
|
defer { _invariantCheck() }
|
||||||
return try nullTerminatedStorage.withContiguousMutableStorageIfAvailable(body)
|
// Do not include the null terminator, it is outside the Collection
|
||||||
|
return try nullTerminatedStorage.withContiguousMutableStorageIfAvailable {
|
||||||
|
var buffer = UnsafeMutableBufferPointer<SystemChar>(
|
||||||
|
start: $0.baseAddress, count: $0.count-1
|
||||||
|
)
|
||||||
|
return try body(&buffer)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension SystemString: Hashable, Codable {}
|
extension SystemString: Hashable, Codable {
|
||||||
|
// Encoder is synthesized; it probably should have been explicit and used
|
||||||
|
// a single-value container, but making that change now is somewhat risky.
|
||||||
|
|
||||||
|
// Decoder is written explicitly to ensure that we validate invariants on
|
||||||
|
// untrusted input.
|
||||||
|
public init(from decoder: any Decoder) throws {
|
||||||
|
let container = try decoder.container(keyedBy: CodingKeys.self)
|
||||||
|
self.nullTerminatedStorage = try container.decode(
|
||||||
|
Storage.self, forKey: .nullTerminatedStorage
|
||||||
|
)
|
||||||
|
guard _invariantsSatisfied() else {
|
||||||
|
throw DecodingError.dataCorruptedError(
|
||||||
|
forKey: .nullTerminatedStorage,
|
||||||
|
in: container,
|
||||||
|
debugDescription:
|
||||||
|
"Encoding does not satisfy the invariants of SystemString"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
extension SystemString {
|
extension SystemString {
|
||||||
// TODO: Below include null terminator, is this desired?
|
|
||||||
|
|
||||||
|
// withSystemChars includes the null terminator
|
||||||
internal func withSystemChars<T>(
|
internal func withSystemChars<T>(
|
||||||
_ f: (UnsafeBufferPointer<SystemChar>) throws -> T
|
_ f: (UnsafeBufferPointer<SystemChar>) throws -> T
|
||||||
) rethrows -> T {
|
) rethrows -> T {
|
||||||
try withContiguousStorageIfAvailable(f)!
|
try nullTerminatedStorage.withContiguousStorageIfAvailable(f)!
|
||||||
}
|
}
|
||||||
|
|
||||||
internal func withCodeUnits<T>(
|
internal func withCodeUnits<T>(
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ final class ErrnoTest: XCTestCase {
|
|||||||
XCTAssert(EHOSTUNREACH == Errno.noRouteToHost.rawValue)
|
XCTAssert(EHOSTUNREACH == Errno.noRouteToHost.rawValue)
|
||||||
XCTAssert(ENOTEMPTY == Errno.directoryNotEmpty.rawValue)
|
XCTAssert(ENOTEMPTY == Errno.directoryNotEmpty.rawValue)
|
||||||
|
|
||||||
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
|
#if SYSTEM_PACKAGE_DARWIN
|
||||||
XCTAssert(EPROCLIM == Errno.tooManyProcesses.rawValue)
|
XCTAssert(EPROCLIM == Errno.tooManyProcesses.rawValue)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -92,7 +92,7 @@ final class ErrnoTest: XCTestCase {
|
|||||||
XCTAssert(EDQUOT == Errno.diskQuotaExceeded.rawValue)
|
XCTAssert(EDQUOT == Errno.diskQuotaExceeded.rawValue)
|
||||||
XCTAssert(ESTALE == Errno.staleNFSFileHandle.rawValue)
|
XCTAssert(ESTALE == Errno.staleNFSFileHandle.rawValue)
|
||||||
|
|
||||||
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
|
#if SYSTEM_PACKAGE_DARWIN
|
||||||
XCTAssert(EBADRPC == Errno.rpcUnsuccessful.rawValue)
|
XCTAssert(EBADRPC == Errno.rpcUnsuccessful.rawValue)
|
||||||
XCTAssert(ERPCMISMATCH == Errno.rpcVersionMismatch.rawValue)
|
XCTAssert(ERPCMISMATCH == Errno.rpcVersionMismatch.rawValue)
|
||||||
XCTAssert(EPROGUNAVAIL == Errno.rpcProgramUnavailable.rawValue)
|
XCTAssert(EPROGUNAVAIL == Errno.rpcProgramUnavailable.rawValue)
|
||||||
@@ -103,7 +103,7 @@ final class ErrnoTest: XCTestCase {
|
|||||||
XCTAssert(ENOLCK == Errno.noLocks.rawValue)
|
XCTAssert(ENOLCK == Errno.noLocks.rawValue)
|
||||||
XCTAssert(ENOSYS == Errno.noFunction.rawValue)
|
XCTAssert(ENOSYS == Errno.noFunction.rawValue)
|
||||||
|
|
||||||
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
|
#if SYSTEM_PACKAGE_DARWIN
|
||||||
XCTAssert(EFTYPE == Errno.badFileTypeOrFormat.rawValue)
|
XCTAssert(EFTYPE == Errno.badFileTypeOrFormat.rawValue)
|
||||||
XCTAssert(EAUTH == Errno.authenticationError.rawValue)
|
XCTAssert(EAUTH == Errno.authenticationError.rawValue)
|
||||||
XCTAssert(ENEEDAUTH == Errno.needAuthenticator.rawValue)
|
XCTAssert(ENEEDAUTH == Errno.needAuthenticator.rawValue)
|
||||||
@@ -113,7 +113,7 @@ final class ErrnoTest: XCTestCase {
|
|||||||
|
|
||||||
XCTAssert(EOVERFLOW == Errno.overflow.rawValue)
|
XCTAssert(EOVERFLOW == Errno.overflow.rawValue)
|
||||||
|
|
||||||
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
|
#if SYSTEM_PACKAGE_DARWIN
|
||||||
XCTAssert(EBADEXEC == Errno.badExecutable.rawValue)
|
XCTAssert(EBADEXEC == Errno.badExecutable.rawValue)
|
||||||
XCTAssert(EBADARCH == Errno.badCPUType.rawValue)
|
XCTAssert(EBADARCH == Errno.badCPUType.rawValue)
|
||||||
XCTAssert(ESHLIBVERS == Errno.sharedLibraryVersionMismatch.rawValue)
|
XCTAssert(ESHLIBVERS == Errno.sharedLibraryVersionMismatch.rawValue)
|
||||||
@@ -125,7 +125,7 @@ final class ErrnoTest: XCTestCase {
|
|||||||
XCTAssert(ENOMSG == Errno.noMessage.rawValue)
|
XCTAssert(ENOMSG == Errno.noMessage.rawValue)
|
||||||
XCTAssert(EILSEQ == Errno.illegalByteSequence.rawValue)
|
XCTAssert(EILSEQ == Errno.illegalByteSequence.rawValue)
|
||||||
|
|
||||||
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
|
#if SYSTEM_PACKAGE_DARWIN
|
||||||
XCTAssert(ENOATTR == Errno.attributeNotFound.rawValue)
|
XCTAssert(ENOATTR == Errno.attributeNotFound.rawValue)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -144,14 +144,14 @@ final class ErrnoTest: XCTestCase {
|
|||||||
XCTAssert(ETOOMANYREFS == Errno.tooManyReferences.rawValue)
|
XCTAssert(ETOOMANYREFS == Errno.tooManyReferences.rawValue)
|
||||||
XCTAssert(EREMOTE == Errno.tooManyRemoteLevels.rawValue)
|
XCTAssert(EREMOTE == Errno.tooManyRemoteLevels.rawValue)
|
||||||
|
|
||||||
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
|
#if SYSTEM_PACKAGE_DARWIN
|
||||||
XCTAssert(ENOPOLICY == Errno.noSuchPolicy.rawValue)
|
XCTAssert(ENOPOLICY == Errno.noSuchPolicy.rawValue)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
XCTAssert(ENOTRECOVERABLE == Errno.notRecoverable.rawValue)
|
XCTAssert(ENOTRECOVERABLE == Errno.notRecoverable.rawValue)
|
||||||
XCTAssert(EOWNERDEAD == Errno.previousOwnerDied.rawValue)
|
XCTAssert(EOWNERDEAD == Errno.previousOwnerDied.rawValue)
|
||||||
|
|
||||||
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
|
#if SYSTEM_PACKAGE_DARWIN
|
||||||
XCTAssert(EQFULL == Errno.outputQueueFull.rawValue)
|
XCTAssert(EQFULL == Errno.outputQueueFull.rawValue)
|
||||||
XCTAssert(ELAST == Errno.lastErrnoValue.rawValue)
|
XCTAssert(ELAST == Errno.lastErrnoValue.rawValue)
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -86,6 +86,30 @@ final class FileOperationsTest: XCTestCase {
|
|||||||
for test in syscallTestCases { test.runAllTests() }
|
for test in syscallTestCases { test.runAllTests() }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testWriteFromEmptyBuffer() throws {
|
||||||
|
let fd = try FileDescriptor.open(FilePath("/dev/null"), .writeOnly)
|
||||||
|
let written1 = try fd.write(toAbsoluteOffset: 0, .init(start: nil, count: 0))
|
||||||
|
XCTAssertEqual(written1, 0)
|
||||||
|
|
||||||
|
let pointer = UnsafeMutableRawPointer.allocate(byteCount: 8, alignment: 8)
|
||||||
|
defer { pointer.deallocate() }
|
||||||
|
let empty = UnsafeRawBufferPointer(start: pointer, count: 0)
|
||||||
|
let written2 = try fd.write(toAbsoluteOffset: 0, empty)
|
||||||
|
XCTAssertEqual(written2, 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
func testReadToEmptyBuffer() throws {
|
||||||
|
let fd = try FileDescriptor.open(FilePath("/dev/random"), .readOnly)
|
||||||
|
let read1 = try fd.read(fromAbsoluteOffset: 0, into: .init(start: nil, count: 0))
|
||||||
|
XCTAssertEqual(read1, 0)
|
||||||
|
|
||||||
|
let pointer = UnsafeMutableRawPointer.allocate(byteCount: 8, alignment: 8)
|
||||||
|
defer { pointer.deallocate() }
|
||||||
|
let empty = UnsafeMutableRawBufferPointer(start: pointer, count: 0)
|
||||||
|
let read2 = try fd.read(fromAbsoluteOffset: 0, into: empty)
|
||||||
|
XCTAssertEqual(read2, 0)
|
||||||
|
}
|
||||||
|
|
||||||
func testHelpers() {
|
func testHelpers() {
|
||||||
// TODO: Test writeAll, writeAll(toAbsoluteOffset), closeAfter
|
// TODO: Test writeAll, writeAll(toAbsoluteOffset), closeAfter
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,129 @@
|
|||||||
|
/*
|
||||||
|
This source file is part of the Swift System open source project
|
||||||
|
|
||||||
|
Copyright (c)2024 Apple Inc. and the Swift System project authors
|
||||||
|
Licensed under Apache License v2.0 with Runtime Library Exception
|
||||||
|
|
||||||
|
See https://swift.org/LICENSE.txt for license information
|
||||||
|
*/
|
||||||
|
|
||||||
|
import XCTest
|
||||||
|
|
||||||
|
#if SYSTEM_PACKAGE
|
||||||
|
@testable import SystemPackage
|
||||||
|
#else
|
||||||
|
@testable import System
|
||||||
|
#endif
|
||||||
|
|
||||||
|
@available(/*System 0.0.1: macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0*/iOS 8, *)
|
||||||
|
final class FilePathDecodableTest: XCTestCase {
|
||||||
|
func testInvalidFilePath() {
|
||||||
|
// _storage is a valid SystemString, but the invariants of FilePath are
|
||||||
|
// violated (specifically, _storage is not normal).
|
||||||
|
let input: [UInt8] = [
|
||||||
|
123, 34, 95,115,116,111,114, 97,103,101, 34, 58,123, 34,110,117,108,108,
|
||||||
|
84,101,114,109,105,110, 97,116,101,100, 83,116,111,114, 97,103,101, 34,
|
||||||
|
58, 91, 49, 48, 57, 44, 45, 55, 54, 44, 53, 53, 44, 55, 49, 44, 49, 52,
|
||||||
|
44, 53, 57, 44, 45, 49, 49, 50, 44, 45, 56, 52, 44, 52, 50, 44, 45, 55,
|
||||||
|
48, 44, 45, 49, 48, 52, 44, 55, 51, 44, 45, 54, 44, 50, 44, 53, 55, 44,
|
||||||
|
54, 50, 44, 45, 56, 55, 44, 45, 53, 44, 45, 54, 53, 44, 45, 51, 57, 44,
|
||||||
|
45, 49, 48, 57, 44, 45, 55, 54, 44, 51, 48, 44, 53, 50, 44, 45, 56, 50,
|
||||||
|
44, 45, 54, 48, 44, 45, 50, 44, 56, 53, 44, 49, 50, 51, 44, 45, 56, 52,
|
||||||
|
44, 45, 53, 56, 44, 49, 49, 52, 44, 49, 44, 45, 49, 49, 54, 44, 56, 48,
|
||||||
|
44, 49, 48, 52, 44, 45, 55, 56, 44, 45, 52, 53, 44, 49, 54, 44, 45, 52,
|
||||||
|
54, 44, 55, 44, 49, 49, 56, 44, 45, 50, 52, 44, 54, 50, 44, 54, 52, 44,
|
||||||
|
45, 52, 49, 44, 45, 49, 48, 51, 44, 53, 44, 45, 55, 53, 44, 50, 50, 44,
|
||||||
|
45, 49, 48, 53, 44, 45, 49, 54, 44, 52, 55, 44, 52, 55, 44, 49, 50, 52,
|
||||||
|
44, 45, 53, 55, 44, 53, 51, 44, 49, 49, 49, 44, 49, 53, 44, 45, 50, 55,
|
||||||
|
44, 54, 54, 44, 45, 49, 54, 44, 49, 48, 50, 44, 49, 48, 54, 44, 49, 51,
|
||||||
|
44, 49, 48, 53, 44, 45, 49, 49, 50, 44, 55, 56, 44, 45, 53, 48, 44, 50,
|
||||||
|
48, 44, 56, 44, 45, 50, 55, 44, 52, 52, 44, 52, 44, 56, 44, 54, 53, 44,
|
||||||
|
50, 51, 44, 57, 55, 44, 45, 50, 56, 44, 56, 56, 44, 52, 50, 44, 45, 51,
|
||||||
|
54, 44, 45, 50, 51, 44, 49, 48, 51, 44, 57, 57, 44, 45, 53, 56, 44, 45,
|
||||||
|
49, 49, 48, 44, 45, 53, 52, 44, 45, 49, 49, 55, 44, 45, 57, 52, 44, 45,
|
||||||
|
55, 50, 44, 50, 57, 44, 45, 50, 52, 44, 45, 56, 52, 44, 53, 55, 44, 45,
|
||||||
|
49, 50, 54, 44, 52, 52, 44, 55, 53, 44, 55, 54, 44, 52, 57, 44, 45, 52,
|
||||||
|
49, 44, 45, 50, 53, 44, 50, 52, 44, 45, 49, 50, 54, 44, 55, 44, 50, 56,
|
||||||
|
44, 45, 52, 56, 44, 56, 55, 44, 51, 49, 44, 45, 49, 49, 53, 44, 55, 44,
|
||||||
|
45, 54, 48, 44, 53, 57, 44, 49, 51, 44, 55, 57, 44, 53, 48, 44, 45, 57,
|
||||||
|
54, 44, 45, 50, 44, 45, 50, 52, 44, 45, 57, 49, 44, 55, 49, 44, 45, 49,
|
||||||
|
50, 53, 44, 52, 50, 44, 45, 56, 52, 44, 52, 44, 53, 57, 44, 49, 50, 53,
|
||||||
|
44, 49, 50, 49, 44, 45, 50, 54, 44, 45, 49, 50, 44, 45, 49, 48, 53, 44,
|
||||||
|
53, 54, 44, 49, 49, 48, 44, 49, 52, 44, 45, 49, 48, 52, 44, 45, 53, 50,
|
||||||
|
44, 45, 53, 56, 44, 45, 54, 44, 45, 50, 54, 44, 45, 52, 55, 44, 53, 57,
|
||||||
|
44, 52, 50, 44, 49, 50, 51, 44, 52, 52, 44, 45, 57, 50, 44, 45, 50, 57,
|
||||||
|
44, 45, 51, 54, 44, 45, 54, 50, 44, 50, 54, 44, 45, 49, 55, 44, 45, 49,
|
||||||
|
48, 44, 45, 56, 49, 44, 54, 49, 44, 52, 55, 44, 45, 57, 52, 44, 45, 49,
|
||||||
|
48, 54, 44, 49, 53, 44, 49, 48, 48, 44, 45, 49, 50, 49, 44, 45, 49, 49,
|
||||||
|
49, 44, 51, 44, 45, 57, 44, 52, 54, 44, 45, 55, 48, 44, 45, 49, 57, 44,
|
||||||
|
52, 56, 44, 45, 49, 50, 44, 45, 57, 49, 44, 45, 50, 48, 44, 49, 51, 44,
|
||||||
|
54, 53, 44, 45, 55, 48, 44, 52, 49, 44, 45, 57, 53, 44, 49, 48, 52, 44,
|
||||||
|
45, 55, 53, 44, 45, 49, 49, 53, 44, 49, 48, 49, 44, 45, 57, 52, 44, 45,
|
||||||
|
49, 50, 51, 44, 45, 51, 53, 44, 45, 50, 49, 44, 45, 52, 50, 44, 45, 51,
|
||||||
|
48, 44, 45, 55, 49, 44, 45, 49, 49, 57, 44, 52, 52, 44, 49, 49, 49, 44,
|
||||||
|
49, 48, 53, 44, 54, 54, 44, 45, 49, 50, 54, 44, 55, 50, 44, 45, 52, 48,
|
||||||
|
44, 49, 50, 49, 44, 45, 50, 49, 44, 52, 50, 44, 45, 55, 56, 44, 49, 50,
|
||||||
|
54, 44, 56, 49, 44, 45, 57, 52, 44, 55, 52, 44, 49, 49, 50, 44, 45, 56,
|
||||||
|
54, 44, 51, 50, 44, 55, 54, 44, 49, 49, 55, 44, 45, 56, 44, 56, 54, 44,
|
||||||
|
49, 48, 51, 44, 54, 50, 44, 49, 49, 55, 44, 54, 55, 44, 45, 56, 54, 44,
|
||||||
|
45, 49, 48, 48, 44, 45, 49, 48, 57, 44, 45, 53, 52, 44, 45, 51, 49, 44,
|
||||||
|
45, 56, 57, 44, 48, 93,125,125,
|
||||||
|
]
|
||||||
|
|
||||||
|
XCTAssertThrowsError(try JSONDecoder().decode(
|
||||||
|
FilePath.self,
|
||||||
|
from: Data(input)
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
func testInvalidSystemString() {
|
||||||
|
// _storage is a SystemString whose invariants are violated; it contains
|
||||||
|
// a non-terminating null byte.
|
||||||
|
let input: [UInt8] = [
|
||||||
|
123, 34, 95,115,116,111,114, 97,103,101, 34, 58,123, 34,110,117,108,108,
|
||||||
|
84,101,114,109,105,110, 97,116,101,100, 83,116,111,114, 97,103,101, 34,
|
||||||
|
58, 91, 49, 49, 49, 44, 48, 44, 45, 49, 54, 44, 57, 49, 44, 52, 54, 44,
|
||||||
|
45, 49, 48, 50, 44, 49, 49, 53, 44, 45, 50, 49, 44, 45, 49, 49, 56, 44,
|
||||||
|
52, 57, 44, 57, 50, 44, 45, 49, 48, 44, 53, 56, 44, 45, 55, 48, 44, 57,
|
||||||
|
55, 44, 56, 44, 57, 57, 44, 48, 93,125, 125
|
||||||
|
]
|
||||||
|
|
||||||
|
XCTAssertThrowsError(try JSONDecoder().decode(
|
||||||
|
FilePath.self,
|
||||||
|
from: Data(input)
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
func testInvalidExample() {
|
||||||
|
// Another misformed example from Johannes that violates FilePath's
|
||||||
|
// invariants by virtue of not being normalized.
|
||||||
|
let input: [UInt8] = [
|
||||||
|
123, 34, 95,115,116,111,114, 97,103,101, 34, 58,123, 34,110,117,108,108,
|
||||||
|
84,101,114,109,105,110, 97,116,101,100, 83,116,111,114, 97,103,101, 34,
|
||||||
|
58, 91, 56, 55, 44, 50, 52, 44, 45, 49, 49, 53, 44, 45, 49, 57, 44, 49,
|
||||||
|
50, 50, 44, 45, 54, 56, 44, 57, 49, 44, 45, 49, 48, 54, 44, 45, 49, 48,
|
||||||
|
48, 44, 45, 49, 49, 52, 44, 53, 54, 44, 45, 54, 53, 44, 49, 49, 56, 44,
|
||||||
|
45, 54, 48, 44, 54, 54, 44, 45, 52, 50, 44, 55, 55, 44, 45, 54, 44, 45,
|
||||||
|
52, 50, 44, 45, 56, 56, 44, 52, 55, 44, 48, 93,125, 125
|
||||||
|
]
|
||||||
|
|
||||||
|
XCTAssertThrowsError(try JSONDecoder().decode(
|
||||||
|
FilePath.self,
|
||||||
|
from: Data(input)
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
func testEmptyString() {
|
||||||
|
// FilePath with an empty (and hence not null-terminated) SystemString.
|
||||||
|
let input: [UInt8] = [
|
||||||
|
123, 34, 95,115,116,111,114, 97,103,101, 34, 58,123, 34,110,117,108,108,
|
||||||
|
84,101,114,109,105,110, 97,116,101,100, 83,116,111,114, 97,103,101, 34,
|
||||||
|
58, 91, 93,125,125
|
||||||
|
]
|
||||||
|
|
||||||
|
XCTAssertThrowsError(try JSONDecoder().decode(
|
||||||
|
FilePath.self,
|
||||||
|
from: Data(input)
|
||||||
|
))
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -38,7 +38,7 @@ final class FileDescriptorTest: XCTestCase {
|
|||||||
XCTAssertEqual(O_CLOEXEC, FileDescriptor.OpenOptions.closeOnExec.rawValue)
|
XCTAssertEqual(O_CLOEXEC, FileDescriptor.OpenOptions.closeOnExec.rawValue)
|
||||||
|
|
||||||
// BSD only
|
// BSD only
|
||||||
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
|
#if SYSTEM_PACKAGE_DARWIN
|
||||||
XCTAssertEqual(O_SHLOCK, FileDescriptor.OpenOptions.sharedLock.rawValue)
|
XCTAssertEqual(O_SHLOCK, FileDescriptor.OpenOptions.sharedLock.rawValue)
|
||||||
XCTAssertEqual(O_EXLOCK, FileDescriptor.OpenOptions.exclusiveLock.rawValue)
|
XCTAssertEqual(O_EXLOCK, FileDescriptor.OpenOptions.exclusiveLock.rawValue)
|
||||||
XCTAssertEqual(O_SYMLINK, FileDescriptor.OpenOptions.symlink.rawValue)
|
XCTAssertEqual(O_SYMLINK, FileDescriptor.OpenOptions.symlink.rawValue)
|
||||||
@@ -49,7 +49,7 @@ final class FileDescriptorTest: XCTestCase {
|
|||||||
XCTAssertEqual(SEEK_CUR, FileDescriptor.SeekOrigin.current.rawValue)
|
XCTAssertEqual(SEEK_CUR, FileDescriptor.SeekOrigin.current.rawValue)
|
||||||
XCTAssertEqual(SEEK_END, FileDescriptor.SeekOrigin.end.rawValue)
|
XCTAssertEqual(SEEK_END, FileDescriptor.SeekOrigin.end.rawValue)
|
||||||
|
|
||||||
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
|
#if SYSTEM_PACKAGE_DARWIN
|
||||||
XCTAssertEqual(SEEK_HOLE, FileDescriptor.SeekOrigin.nextHole.rawValue)
|
XCTAssertEqual(SEEK_HOLE, FileDescriptor.SeekOrigin.nextHole.rawValue)
|
||||||
XCTAssertEqual(SEEK_DATA, FileDescriptor.SeekOrigin.nextData.rawValue)
|
XCTAssertEqual(SEEK_DATA, FileDescriptor.SeekOrigin.nextData.rawValue)
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ See https://swift.org/LICENSE.txt for license information
|
|||||||
function(get_swift_host_arch result_var_name)
|
function(get_swift_host_arch result_var_name)
|
||||||
if("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64")
|
if("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64")
|
||||||
set("${result_var_name}" "x86_64" PARENT_SCOPE)
|
set("${result_var_name}" "x86_64" PARENT_SCOPE)
|
||||||
elseif ("${CMAKE_SYSTEM_PROCESSOR}" MATCHES "AArch64|aarch64|arm64")
|
elseif ("${CMAKE_SYSTEM_PROCESSOR}" MATCHES "AArch64|aarch64|arm64|ARM64")
|
||||||
if(CMAKE_SYSTEM_NAME MATCHES Darwin)
|
if(CMAKE_SYSTEM_NAME MATCHES Darwin)
|
||||||
set("${result_var_name}" "arm64" PARENT_SCOPE)
|
set("${result_var_name}" "arm64" PARENT_SCOPE)
|
||||||
else()
|
else()
|
||||||
|
|||||||
Reference in new issue
Block a user