mirror of
https://github.com/apple/swift-system
synced 2026-11-30 05:28:49 +00:00
Compare 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 | ||
|
|
025bcb1165 | ||
|
|
f5e4aac51b | ||
|
|
94fa6bd2ff | ||
|
|
a552fda216 | ||
|
|
bdb13a5a80 | ||
|
|
3920df78d9 | ||
|
|
469ede0fa2 | ||
|
|
afe2d35d0b | ||
|
|
25380a1bea | ||
|
|
74eb6f4ef8 | ||
|
|
6db5a4a43b | ||
|
|
5ba9e8fa77 | ||
|
|
914c782b96 | ||
|
|
82a6704912 | ||
|
|
bd5a7bb703 | ||
|
|
147ebc053a | ||
|
|
5c18991f29 | ||
|
|
7bb5279b57 | ||
|
|
865fd70605 | ||
|
|
ca6e888455 | ||
|
|
fea7d5030d | ||
|
|
d90bf8529a | ||
|
|
02daf4b6a7 | ||
|
|
7fab65f340 | ||
|
|
5d3519dcef | ||
|
|
23ac190631 | ||
|
|
a77a331dc7 | ||
|
|
1d5e35a460 | ||
|
|
fd82b5a0ce | ||
|
|
0c24d31e08 | ||
|
|
1daa0c9677 | ||
|
|
836bc4557b | ||
|
|
5d68cf0eca | ||
|
|
5703dc2b4d | ||
|
|
2fa26782e1 | ||
|
|
0c291a65c2 | ||
|
|
0ac080ea56 | ||
|
|
d2c4e4507a | ||
|
|
78847afcd4 | ||
|
|
689390f50f | ||
|
|
ce8b491073 | ||
|
|
39774ef16a | ||
|
|
58a2725013 | ||
|
|
e520e61616 | ||
|
|
4f36710d0b | ||
|
|
591ff41944 |
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"
|
||||||
|
}
|
||||||
+2
-7
@@ -8,7 +8,7 @@ See https://swift.org/LICENSE.txt for license information
|
|||||||
#]]
|
#]]
|
||||||
|
|
||||||
cmake_minimum_required(VERSION 3.16.0)
|
cmake_minimum_required(VERSION 3.16.0)
|
||||||
project(swift-system
|
project(SwiftSystem
|
||||||
LANGUAGES C Swift)
|
LANGUAGES C Swift)
|
||||||
|
|
||||||
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/modules)
|
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/modules)
|
||||||
@@ -21,9 +21,4 @@ set(CMAKE_Swift_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/swift)
|
|||||||
include(SwiftSupport)
|
include(SwiftSupport)
|
||||||
|
|
||||||
add_subdirectory(Sources)
|
add_subdirectory(Sources)
|
||||||
|
add_subdirectory(cmake/modules)
|
||||||
get_property(SWIFT_SYSTEM_EXPORTS GLOBAL PROPERTY SWIFT_SYSTEM_EXPORTS)
|
|
||||||
export(TARGETS ${SWIFT_SYSTEM_EXPORTS}
|
|
||||||
NAMESPACE SwiftSystem::
|
|
||||||
FILE swift-system-config.cmake
|
|
||||||
EXPORT_LINK_INTERFACE_LIBRARIES)
|
|
||||||
+34
-23
@@ -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,25 +11,12 @@
|
|||||||
|
|
||||||
import PackageDescription
|
import PackageDescription
|
||||||
|
|
||||||
let targets: [PackageDescription.Target] = [
|
let DarwinPlatforms: [Platform]
|
||||||
.target(
|
#if swift(<5.9)
|
||||||
name: "SystemPackage",
|
DarwinPlatforms = [.macOS, .iOS, .watchOS, .tvOS]
|
||||||
dependencies: ["CSystem"],
|
#else
|
||||||
path: "Sources/System",
|
DarwinPlatforms = [.macOS, .iOS, .watchOS, .tvOS, .visionOS]
|
||||||
swiftSettings: [
|
#endif
|
||||||
.define("SYSTEM_PACKAGE"),
|
|
||||||
.define("ENABLE_MOCKING", .when(configuration: .debug))
|
|
||||||
]),
|
|
||||||
.target(
|
|
||||||
name: "CSystem",
|
|
||||||
dependencies: []),
|
|
||||||
.testTarget(
|
|
||||||
name: "SystemTests",
|
|
||||||
dependencies: ["SystemPackage"],
|
|
||||||
swiftSettings: [
|
|
||||||
.define("SYSTEM_PACKAGE")
|
|
||||||
]),
|
|
||||||
]
|
|
||||||
|
|
||||||
let package = Package(
|
let package = Package(
|
||||||
name: "swift-system",
|
name: "swift-system",
|
||||||
@@ -38,5 +24,30 @@ let package = Package(
|
|||||||
.library(name: "SystemPackage", targets: ["SystemPackage"]),
|
.library(name: "SystemPackage", targets: ["SystemPackage"]),
|
||||||
],
|
],
|
||||||
dependencies: [],
|
dependencies: [],
|
||||||
targets: targets
|
targets: [
|
||||||
|
.target(
|
||||||
|
name: "CSystem",
|
||||||
|
dependencies: [],
|
||||||
|
exclude: ["CMakeLists.txt"]),
|
||||||
|
.target(
|
||||||
|
name: "SystemPackage",
|
||||||
|
dependencies: ["CSystem"],
|
||||||
|
path: "Sources/System",
|
||||||
|
exclude: ["CMakeLists.txt"],
|
||||||
|
cSettings: [
|
||||||
|
.define("_CRT_SECURE_NO_WARNINGS")
|
||||||
|
],
|
||||||
|
swiftSettings: [
|
||||||
|
.define("SYSTEM_PACKAGE"),
|
||||||
|
.define("SYSTEM_PACKAGE_DARWIN", .when(platforms: DarwinPlatforms)),
|
||||||
|
.define("ENABLE_MOCKING", .when(configuration: .debug))
|
||||||
|
]),
|
||||||
|
.testTarget(
|
||||||
|
name: "SystemTests",
|
||||||
|
dependencies: ["SystemPackage"],
|
||||||
|
swiftSettings: [
|
||||||
|
.define("SYSTEM_PACKAGE"),
|
||||||
|
.define("SYSTEM_PACKAGE_DARWIN", .when(platforms: DarwinPlatforms)),
|
||||||
|
]),
|
||||||
|
]
|
||||||
)
|
)
|
||||||
@@ -28,16 +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: "0.0.1"),
|
.package(url: "https://github.com/apple/swift-system", from: "1.3.0"),
|
||||||
```
|
|
||||||
|
|
||||||
Because `SystemPackage` is under active development,
|
|
||||||
source-stability is only guaranteed within minor versions (e.g. between `0.0.3` and `0.0.4`).
|
|
||||||
If you don't want potentially source-breaking package updates,
|
|
||||||
use this dependency specification instead:
|
|
||||||
|
|
||||||
```swift
|
|
||||||
.package(url: "https://github.com/apple/swift-system", .upToNextMinor(from: "0.0.1")),
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Finally, include `"SystemPackage"` as a dependency for your executable target:
|
Finally, include `"SystemPackage"` as a dependency for your executable target:
|
||||||
@@ -46,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: "0.0.1"),
|
.package(url: "https://github.com/apple/swift-system", from: "1.3.0"),
|
||||||
// other dependencies
|
// other dependencies
|
||||||
],
|
],
|
||||||
targets: [
|
targets: [
|
||||||
@@ -58,6 +49,12 @@ let package = Package(
|
|||||||
)
|
)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Source Stability
|
||||||
|
|
||||||
|
The Swift System package is source stable. The version numbers follow [Semantic Versioning][semver] -- source breaking changes to public API can only land in a new major version.
|
||||||
|
|
||||||
|
[semver]: https://semver.org
|
||||||
|
|
||||||
## Contributing
|
## Contributing
|
||||||
|
|
||||||
Before contributing, please read [CONTRIBUTING.md](CONTRIBUTING.md).
|
Before contributing, please read [CONTRIBUTING.md](CONTRIBUTING.md).
|
||||||
|
|||||||
@@ -12,4 +12,9 @@ target_include_directories(CSystem INTERFACE
|
|||||||
include)
|
include)
|
||||||
|
|
||||||
|
|
||||||
|
install(FILES
|
||||||
|
include/CSystemLinux.h
|
||||||
|
include/CSystemWindows.h
|
||||||
|
include/module.modulemap
|
||||||
|
DESTINATION include/CSystem)
|
||||||
set_property(GLOBAL APPEND PROPERTY SWIFT_SYSTEM_EXPORTS CSystem)
|
set_property(GLOBAL APPEND PROPERTY SWIFT_SYSTEM_EXPORTS CSystem)
|
||||||
@@ -7,7 +7,7 @@ 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
|
||||||
#]]
|
#]]
|
||||||
|
|
||||||
add_library(System
|
add_library(SystemPackage
|
||||||
Errno.swift
|
Errno.swift
|
||||||
FileDescriptor.swift
|
FileDescriptor.swift
|
||||||
FileHelpers.swift
|
FileHelpers.swift
|
||||||
@@ -17,7 +17,9 @@ add_library(System
|
|||||||
SystemString.swift
|
SystemString.swift
|
||||||
Util.swift
|
Util.swift
|
||||||
UtilConsumers.swift)
|
UtilConsumers.swift)
|
||||||
target_sources(System PRIVATE
|
set_target_properties(SystemPackage PROPERTIES
|
||||||
|
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY})
|
||||||
|
target_sources(SystemPackage PRIVATE
|
||||||
FilePath/FilePath.swift
|
FilePath/FilePath.swift
|
||||||
FilePath/FilePathComponents.swift
|
FilePath/FilePathComponents.swift
|
||||||
FilePath/FilePathComponentView.swift
|
FilePath/FilePathComponentView.swift
|
||||||
@@ -25,16 +27,20 @@ target_sources(System PRIVATE
|
|||||||
FilePath/FilePathString.swift
|
FilePath/FilePathString.swift
|
||||||
FilePath/FilePathSyntax.swift
|
FilePath/FilePathSyntax.swift
|
||||||
FilePath/FilePathWindows.swift)
|
FilePath/FilePathWindows.swift)
|
||||||
target_sources(System PRIVATE
|
target_sources(SystemPackage PRIVATE
|
||||||
Internals/CInterop.swift
|
Internals/CInterop.swift
|
||||||
Internals/Constants.swift
|
Internals/Constants.swift
|
||||||
Internals/Exports.swift
|
Internals/Exports.swift
|
||||||
Internals/Mocking.swift
|
Internals/Mocking.swift
|
||||||
Internals/Syscalls.swift
|
Internals/Syscalls.swift
|
||||||
Internals/WindowsSyscallAdapters.swift)
|
Internals/WindowsSyscallAdapters.swift)
|
||||||
target_link_libraries(System PRIVATE
|
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(System)
|
_install_target(SystemPackage)
|
||||||
set_property(GLOBAL APPEND PROPERTY SWIFT_SYSTEM_EXPORTS System)
|
set_property(GLOBAL APPEND PROPERTY SWIFT_SYSTEM_EXPORTS SystemPackage)
|
||||||
+16
-16
@@ -10,7 +10,7 @@
|
|||||||
/// An error number used by system calls to communicate what kind of error
|
/// An error number used by system calls to communicate what kind of error
|
||||||
/// occurred.
|
/// occurred.
|
||||||
@frozen
|
@frozen
|
||||||
// @available(macOS 10.16, 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, *)*/
|
||||||
public struct Errno: RawRepresentable, Error, Hashable, Codable {
|
public struct Errno: RawRepresentable, Error, Hashable, Codable {
|
||||||
/// The raw C error number.
|
/// The raw C error number.
|
||||||
@_alwaysEmitIntoClient
|
@_alwaysEmitIntoClient
|
||||||
@@ -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.
|
||||||
@@ -1376,7 +1376,7 @@ public struct Errno: RawRepresentable, Error, Hashable, Codable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Constants defined in header but not man page
|
// Constants defined in header but not man page
|
||||||
// @available(macOS 10.16, 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 Errno {
|
extension Errno {
|
||||||
|
|
||||||
/// Operation would block.
|
/// Operation would block.
|
||||||
@@ -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`.
|
||||||
@@ -1470,7 +1470,7 @@ extension Errno {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// @available(macOS 10.16, 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 Errno {
|
extension Errno {
|
||||||
// TODO: We want to provide safe access to `errno`, but we need a
|
// TODO: We want to provide safe access to `errno`, but we need a
|
||||||
// release-barrier to do so.
|
// release-barrier to do so.
|
||||||
@@ -1485,14 +1485,14 @@ extension Errno {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Use "hidden" entry points for `NSError` bridging
|
// Use "hidden" entry points for `NSError` bridging
|
||||||
// @available(macOS 10.16, 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 Errno {
|
extension Errno {
|
||||||
public var _code: Int { Int(rawValue) }
|
public var _code: Int { Int(rawValue) }
|
||||||
|
|
||||||
public var _domain: String { "NSPOSIXErrorDomain" }
|
public var _domain: String { "NSPOSIXErrorDomain" }
|
||||||
}
|
}
|
||||||
|
|
||||||
// @available(macOS 10.16, 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 Errno: CustomStringConvertible, CustomDebugStringConvertible {
|
extension Errno: CustomStringConvertible, CustomDebugStringConvertible {
|
||||||
/// A textual representation of the most recent error
|
/// A textual representation of the most recent error
|
||||||
/// returned by a system call.
|
/// returned by a system call.
|
||||||
@@ -1512,7 +1512,7 @@ extension Errno: CustomStringConvertible, CustomDebugStringConvertible {
|
|||||||
public var debugDescription: String { self.description }
|
public var debugDescription: String { self.description }
|
||||||
}
|
}
|
||||||
|
|
||||||
// @available(macOS 10.16, 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 Errno {
|
extension Errno {
|
||||||
@_alwaysEmitIntoClient
|
@_alwaysEmitIntoClient
|
||||||
public static func ~=(_ lhs: Errno, _ rhs: Error) -> Bool {
|
public static func ~=(_ lhs: Errno, _ rhs: Error) -> Bool {
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
/// of `FileDescriptor` values,
|
/// of `FileDescriptor` values,
|
||||||
/// in the same way as you manage a raw C file handle.
|
/// in the same way as you manage a raw C file handle.
|
||||||
@frozen
|
@frozen
|
||||||
// @available(macOS 10.16, 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, *)*/
|
||||||
public struct FileDescriptor: RawRepresentable, Hashable, Codable {
|
public struct FileDescriptor: RawRepresentable, Hashable, Codable {
|
||||||
/// The raw C file handle.
|
/// The raw C file handle.
|
||||||
@_alwaysEmitIntoClient
|
@_alwaysEmitIntoClient
|
||||||
@@ -40,7 +40,7 @@ extension FileDescriptor {
|
|||||||
public static var standardError: FileDescriptor { .init(rawValue: 2) }
|
public static var standardError: FileDescriptor { .init(rawValue: 2) }
|
||||||
}
|
}
|
||||||
|
|
||||||
// @available(macOS 10.16, 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 FileDescriptor {
|
extension FileDescriptor {
|
||||||
/// The desired read and write access for a newly opened file.
|
/// The desired read and write access for a newly opened file.
|
||||||
@frozen
|
@frozen
|
||||||
@@ -106,7 +106,7 @@ extension FileDescriptor {
|
|||||||
/// the system doesn't wait for the device or file
|
/// the system doesn't wait for the device or file
|
||||||
/// to be ready or available.
|
/// to be ready or available.
|
||||||
/// If the
|
/// If the
|
||||||
/// <doc:System/FileDescriptor/open(_:_:options:permissions:)-10dcs>
|
/// <doc:FileDescriptor/open(_:_:options:permissions:retryOnInterrupt:)-2266j>
|
||||||
/// call would result in the process being blocked for some reason,
|
/// call would result in the process being blocked for some reason,
|
||||||
/// that method returns immediately.
|
/// that method returns immediately.
|
||||||
/// This flag also has the effect of making all
|
/// This flag also has the effect of making all
|
||||||
@@ -164,14 +164,14 @@ extension FileDescriptor {
|
|||||||
/// expecting that it doesn't exist.
|
/// expecting that it doesn't exist.
|
||||||
///
|
///
|
||||||
/// If this option and ``create`` are both specified and the file exists,
|
/// If this option and ``create`` are both specified and the file exists,
|
||||||
/// <doc:System/FileDescriptor/open(_:_:options:permissions:)-10dcs>
|
/// <doc:FileDescriptor/open(_:_:options:permissions:retryOnInterrupt:)-2266j>
|
||||||
/// returns an error instead of creating the file.
|
/// returns an error instead of creating the file.
|
||||||
/// You can use this, for example,
|
/// You can use this, for example,
|
||||||
/// to implement a simple exclusive-access locking mechanism.
|
/// to implement a simple exclusive-access locking mechanism.
|
||||||
///
|
///
|
||||||
/// If this option and ``create`` are both specified
|
/// If this option and ``create`` are both specified
|
||||||
/// and the last component of the file's path is a symbolic link,
|
/// and the last component of the file's path is a symbolic link,
|
||||||
/// <doc:System/FileDescriptor/open(_:_:options:permissions:)-10dcs>
|
/// <doc:FileDescriptor/open(_:_:options:permissions:retryOnInterrupt:)-2266j>
|
||||||
/// fails even if the symbolic link points to a nonexistent name.
|
/// fails even if the symbolic link points to a nonexistent name.
|
||||||
///
|
///
|
||||||
/// The corresponding C constant is `O_EXCL`.
|
/// The corresponding C constant is `O_EXCL`.
|
||||||
@@ -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.
|
||||||
///
|
///
|
||||||
@@ -223,7 +223,7 @@ extension FileDescriptor {
|
|||||||
///
|
///
|
||||||
/// If you specify this option
|
/// If you specify this option
|
||||||
/// and the file path you pass to
|
/// and the file path you pass to
|
||||||
/// <doc:System/FileDescriptor/open(_:_:options:permissions:)-10dcs>
|
/// <doc:FileDescriptor/open(_:_:options:permissions:retryOnInterrupt:)-2266j>
|
||||||
/// is a symbolic link,
|
/// is a symbolic link,
|
||||||
/// then that open operation fails.
|
/// then that open operation fails.
|
||||||
///
|
///
|
||||||
@@ -234,15 +234,29 @@ extension FileDescriptor {
|
|||||||
@_alwaysEmitIntoClient
|
@_alwaysEmitIntoClient
|
||||||
@available(*, unavailable, renamed: "noFollow")
|
@available(*, unavailable, renamed: "noFollow")
|
||||||
public static var O_NOFOLLOW: OpenOptions { noFollow }
|
public static var O_NOFOLLOW: OpenOptions { noFollow }
|
||||||
|
|
||||||
|
/// Indicates that opening the file only succeeds if the file is a directory.
|
||||||
|
///
|
||||||
|
/// If you specify this option and the file path you pass to
|
||||||
|
/// <doc:FileDescriptor/open(_:_:options:permissions:retryOnInterrupt:)-2266j>
|
||||||
|
/// is a not a directory, then that open operation fails.
|
||||||
|
///
|
||||||
|
/// The corresponding C constant is `O_DIRECTORY`.
|
||||||
|
@_alwaysEmitIntoClient
|
||||||
|
public static var directory: OpenOptions { OpenOptions(_O_DIRECTORY) }
|
||||||
|
|
||||||
|
@_alwaysEmitIntoClient
|
||||||
|
@available(*, unavailable, renamed: "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.
|
||||||
///
|
///
|
||||||
/// If you specify this option
|
/// If you specify this option
|
||||||
/// and the file path you pass to
|
/// and the file path you pass to
|
||||||
/// <doc:System/FileDescriptor/open(_:_:options:permissions:)-10dcs>
|
/// <doc:FileDescriptor/open(_:_:options:permissions:retryOnInterrupt:)-2266j>
|
||||||
/// is a symbolic link,
|
/// is a symbolic link,
|
||||||
/// then the link itself is opened instead of what it links to.
|
/// then the link itself is opened instead of what it links to.
|
||||||
///
|
///
|
||||||
@@ -339,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.
|
||||||
///
|
///
|
||||||
@@ -371,7 +385,7 @@ extension FileDescriptor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// @available(macOS 10.16, 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 FileDescriptor.AccessMode
|
extension FileDescriptor.AccessMode
|
||||||
: CustomStringConvertible, CustomDebugStringConvertible
|
: CustomStringConvertible, CustomDebugStringConvertible
|
||||||
{
|
{
|
||||||
@@ -390,7 +404,7 @@ extension FileDescriptor.AccessMode
|
|||||||
public var debugDescription: String { self.description }
|
public var debugDescription: String { self.description }
|
||||||
}
|
}
|
||||||
|
|
||||||
// @available(macOS 10.16, 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 FileDescriptor.SeekOrigin
|
extension FileDescriptor.SeekOrigin
|
||||||
: CustomStringConvertible, CustomDebugStringConvertible
|
: CustomStringConvertible, CustomDebugStringConvertible
|
||||||
{
|
{
|
||||||
@@ -401,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
|
||||||
@@ -413,14 +427,14 @@ extension FileDescriptor.SeekOrigin
|
|||||||
public var debugDescription: String { self.description }
|
public var debugDescription: String { self.description }
|
||||||
}
|
}
|
||||||
|
|
||||||
// @available(macOS 10.16, 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 FileDescriptor.OpenOptions
|
extension FileDescriptor.OpenOptions
|
||||||
: CustomStringConvertible, CustomDebugStringConvertible
|
: CustomStringConvertible, CustomDebugStringConvertible
|
||||||
{
|
{
|
||||||
/// 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"),
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
See https://swift.org/LICENSE.txt for license information
|
See https://swift.org/LICENSE.txt for license information
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// @available(macOS 10.16, 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 FileDescriptor {
|
extension FileDescriptor {
|
||||||
/// Runs a closure and then closes the file descriptor, even if an error occurs.
|
/// Runs a closure and then closes the file descriptor, even if an error occurs.
|
||||||
///
|
///
|
||||||
@@ -46,9 +46,6 @@ extension FileDescriptor {
|
|||||||
/// increments that position by the number of bytes written.
|
/// increments that position by the number of bytes written.
|
||||||
/// See also ``seek(offset:from:)``.
|
/// See also ``seek(offset:from:)``.
|
||||||
///
|
///
|
||||||
/// This method either writes the entire contents of `sequence`,
|
|
||||||
/// or throws an error if only part of the content was written.
|
|
||||||
///
|
|
||||||
/// If `sequence` doesn't implement
|
/// If `sequence` doesn't implement
|
||||||
/// the <doc://com.apple.documentation/documentation/swift/sequence/3128824-withcontiguousstorageifavailable> method,
|
/// the <doc://com.apple.documentation/documentation/swift/sequence/3128824-withcontiguousstorageifavailable> method,
|
||||||
/// temporary space will be allocated as needed.
|
/// temporary space will be allocated as needed.
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
See https://swift.org/LICENSE.txt for license information
|
See https://swift.org/LICENSE.txt for license information
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// @available(macOS 10.16, 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 FileDescriptor {
|
extension FileDescriptor {
|
||||||
/// Opens or creates a file for reading or writing.
|
/// Opens or creates a file for reading or writing.
|
||||||
///
|
///
|
||||||
@@ -185,7 +185,7 @@ extension FileDescriptor {
|
|||||||
/// The <doc://com.apple.documentation/documentation/swift/unsafemutablerawbufferpointer/3019191-count> property of `buffer`
|
/// The <doc://com.apple.documentation/documentation/swift/unsafemutablerawbufferpointer/3019191-count> property of `buffer`
|
||||||
/// determines the maximum number of bytes that are read into that buffer.
|
/// determines the maximum number of bytes that are read into that buffer.
|
||||||
///
|
///
|
||||||
/// Unlike <doc:System/FileDescriptor/read(into:retryOnInterrupt:)>,
|
/// Unlike <doc:FileDescriptor/read(into:retryOnInterrupt:)>,
|
||||||
/// this method leaves the file's existing offset unchanged.
|
/// this method leaves the file's existing offset unchanged.
|
||||||
///
|
///
|
||||||
/// The corresponding C function is `pread`.
|
/// The corresponding C function is `pread`.
|
||||||
@@ -337,7 +337,7 @@ extension FileDescriptor {
|
|||||||
///
|
///
|
||||||
/// The corresponding C functions are `dup` and `dup2`.
|
/// The corresponding C functions are `dup` and `dup2`.
|
||||||
@_alwaysEmitIntoClient
|
@_alwaysEmitIntoClient
|
||||||
// @available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
|
/*System 0.0.2, @available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)*/
|
||||||
public func duplicate(
|
public func duplicate(
|
||||||
as target: FileDescriptor? = nil,
|
as target: FileDescriptor? = nil,
|
||||||
retryOnInterrupt: Bool = true
|
retryOnInterrupt: Bool = true
|
||||||
@@ -345,7 +345,7 @@ extension FileDescriptor {
|
|||||||
try _duplicate(as: target, retryOnInterrupt: retryOnInterrupt).get()
|
try _duplicate(as: target, retryOnInterrupt: retryOnInterrupt).get()
|
||||||
}
|
}
|
||||||
|
|
||||||
// @available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
|
/*System 0.0.2, @available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)*/
|
||||||
@usableFromInline
|
@usableFromInline
|
||||||
internal func _duplicate(
|
internal func _duplicate(
|
||||||
as target: FileDescriptor?,
|
as target: FileDescriptor?,
|
||||||
@@ -371,3 +371,80 @@ extension FileDescriptor {
|
|||||||
fatalError("Not implemented")
|
fatalError("Not implemented")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !os(Windows)
|
||||||
|
/*System 1.1.0, @available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)*/
|
||||||
|
extension FileDescriptor {
|
||||||
|
/// Create a pipe, a unidirectional data channel which can be used for interprocess communication.
|
||||||
|
///
|
||||||
|
/// - Returns: The pair of file descriptors.
|
||||||
|
///
|
||||||
|
/// The corresponding C function is `pipe`.
|
||||||
|
@_alwaysEmitIntoClient
|
||||||
|
/*System 1.1.0, @available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)*/
|
||||||
|
public static func pipe() throws -> (readEnd: FileDescriptor, writeEnd: FileDescriptor) {
|
||||||
|
try _pipe().get()
|
||||||
|
}
|
||||||
|
|
||||||
|
/*System 1.1.0, @available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)*/
|
||||||
|
@usableFromInline
|
||||||
|
internal static func _pipe() -> Result<(readEnd: FileDescriptor, writeEnd: FileDescriptor), Errno> {
|
||||||
|
var fds: (Int32, Int32) = (-1, -1)
|
||||||
|
return withUnsafeMutablePointer(to: &fds) { pointer in
|
||||||
|
pointer.withMemoryRebound(to: Int32.self, capacity: 2) { fds in
|
||||||
|
valueOrErrno(retryOnInterrupt: false) {
|
||||||
|
system_pipe(fds)
|
||||||
|
}.map { _ in (.init(rawValue: fds[0]), .init(rawValue: fds[1])) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if !os(Windows)
|
||||||
|
/*System 1.2.0, @available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)*/
|
||||||
|
extension FileDescriptor {
|
||||||
|
/// Truncate or extend the file referenced by this file descriptor.
|
||||||
|
///
|
||||||
|
/// - Parameters:
|
||||||
|
/// - newSize: The length in bytes to resize the file to.
|
||||||
|
/// - retryOnInterrupt: Whether to retry the write operation
|
||||||
|
/// if it throws ``Errno/interrupted``. The default is `true`.
|
||||||
|
/// Pass `false` to try only once and throw an error upon interruption.
|
||||||
|
///
|
||||||
|
/// The file referenced by this file descriptor will by truncated (or extended) to `newSize`.
|
||||||
|
///
|
||||||
|
/// If the current size of the file exceeds `newSize`, any extra data is discarded. If the current
|
||||||
|
/// size of the file is smaller than `newSize`, the file is extended and filled with zeros to the
|
||||||
|
/// provided size.
|
||||||
|
///
|
||||||
|
/// This function requires that the file has been opened for writing.
|
||||||
|
///
|
||||||
|
/// - Note: This function does not modify the current offset for any open file descriptors
|
||||||
|
/// associated with the file.
|
||||||
|
///
|
||||||
|
/// The corresponding C function is `ftruncate`.
|
||||||
|
/*System 1.2.0, @available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)*/
|
||||||
|
@_alwaysEmitIntoClient
|
||||||
|
public func resize(
|
||||||
|
to newSize: Int64,
|
||||||
|
retryOnInterrupt: Bool = true
|
||||||
|
) throws {
|
||||||
|
try _resize(
|
||||||
|
to: newSize,
|
||||||
|
retryOnInterrupt: retryOnInterrupt
|
||||||
|
).get()
|
||||||
|
}
|
||||||
|
|
||||||
|
/*System 1.2.0, @available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)*/
|
||||||
|
@usableFromInline
|
||||||
|
internal func _resize(
|
||||||
|
to newSize: Int64,
|
||||||
|
retryOnInterrupt: Bool
|
||||||
|
) -> Result<(), Errno> {
|
||||||
|
nothingOrErrno(retryOnInterrupt: retryOnInterrupt) {
|
||||||
|
system_ftruncate(self.rawValue, _COffT(newSize))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
@@ -16,7 +16,7 @@
|
|||||||
/// encoding.
|
/// encoding.
|
||||||
///
|
///
|
||||||
/// On construction, `FilePath` will normalize separators by removing
|
/// On construction, `FilePath` will normalize separators by removing
|
||||||
/// reduncant intermediary separators and stripping any trailing separators.
|
/// redundant intermediary separators and stripping any trailing separators.
|
||||||
/// On Windows, `FilePath` will also normalize forward slashes `/` into
|
/// On Windows, `FilePath` will also normalize forward slashes `/` into
|
||||||
/// backslashes `\`, as preferred by the platform.
|
/// backslashes `\`, as preferred by the platform.
|
||||||
///
|
///
|
||||||
@@ -28,11 +28,8 @@
|
|||||||
/// let fd = try FileDescriptor.open(path, .writeOnly, options: .append)
|
/// let fd = try FileDescriptor.open(path, .writeOnly, options: .append)
|
||||||
/// try fd.closeAfter { try fd.writeAll(message.utf8) }
|
/// try fd.closeAfter { try fd.writeAll(message.utf8) }
|
||||||
///
|
///
|
||||||
/// TODO(docs): Section on all the new syntactic operations, lexical normalization, decomposition,
|
|
||||||
/// components, etc.
|
|
||||||
///
|
|
||||||
/// File paths conform to the
|
/// File paths conform to the
|
||||||
/// and <doc://com.apple.documentation/documentation/swift/equatable>
|
/// <doc://com.apple.documentation/documentation/swift/equatable>
|
||||||
/// and <doc://com.apple.documentation/documentation/swift/hashable> protocols
|
/// and <doc://com.apple.documentation/documentation/swift/hashable> protocols
|
||||||
/// by performing the protocols' operations on their raw byte contents.
|
/// by performing the protocols' operations on their raw byte contents.
|
||||||
/// This conformance allows file paths to be used,
|
/// This conformance allows file paths to be used,
|
||||||
@@ -40,7 +37,10 @@
|
|||||||
/// However, the rules for path equivalence
|
/// However, the rules for path equivalence
|
||||||
/// are file-system–specific and have additional considerations
|
/// are file-system–specific and have additional considerations
|
||||||
/// like case insensitivity, Unicode normalization, and symbolic links.
|
/// like case insensitivity, Unicode normalization, and symbolic links.
|
||||||
// @available(macOS 10.16, iOS 14.0, watchOS 7.0, tvOS 14.0, *)
|
///
|
||||||
|
// TODO(docs): Section on all the new syntactic operations, lexical normalization, decomposition,
|
||||||
|
// components, etc.
|
||||||
|
/*System 0.0.1, @available(macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0, *)*/
|
||||||
public struct FilePath {
|
public struct FilePath {
|
||||||
internal var _storage: SystemString
|
internal var _storage: SystemString
|
||||||
|
|
||||||
@@ -60,12 +60,29 @@ public struct FilePath {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// @available(macOS 10.16, 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 {
|
extension FilePath {
|
||||||
/// The length of the file path, excluding the null terminator.
|
/// The length of the file path, excluding the null terminator.
|
||||||
public var length: Int { _storage.length }
|
public var length: Int { _storage.length }
|
||||||
}
|
}
|
||||||
|
|
||||||
// @available(macOS 10.16, 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"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,7 +9,7 @@
|
|||||||
|
|
||||||
// MARK: - API
|
// MARK: - API
|
||||||
|
|
||||||
// @available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
|
/*System 0.0.2, @available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)*/
|
||||||
extension FilePath {
|
extension FilePath {
|
||||||
/// A bidirectional, range replaceable collection of the non-root components
|
/// A bidirectional, range replaceable collection of the non-root components
|
||||||
/// that make up a file path.
|
/// that make up a file path.
|
||||||
@@ -89,7 +89,7 @@ extension FilePath {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// @available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
|
/*System 0.0.2, @available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)*/
|
||||||
extension FilePath.ComponentView: BidirectionalCollection {
|
extension FilePath.ComponentView: BidirectionalCollection {
|
||||||
public typealias Element = FilePath.Component
|
public typealias Element = FilePath.Component
|
||||||
public struct Index: Comparable, Hashable {
|
public struct Index: Comparable, Hashable {
|
||||||
@@ -123,7 +123,7 @@ extension FilePath.ComponentView: BidirectionalCollection {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// @available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
|
/*System 0.0.2, @available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)*/
|
||||||
extension FilePath.ComponentView: RangeReplaceableCollection {
|
extension FilePath.ComponentView: RangeReplaceableCollection {
|
||||||
public init() {
|
public init() {
|
||||||
self.init(FilePath())
|
self.init(FilePath())
|
||||||
@@ -173,7 +173,7 @@ extension FilePath.ComponentView: RangeReplaceableCollection {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// @available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
|
/*System 0.0.2, @available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)*/
|
||||||
extension FilePath {
|
extension FilePath {
|
||||||
/// Create a file path from a root and a collection of components.
|
/// Create a file path from a root and a collection of components.
|
||||||
public init<C: Collection>(
|
public init<C: Collection>(
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
|
|
||||||
// MARK: - API
|
// MARK: - API
|
||||||
|
|
||||||
// @available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
|
/*System 0.0.2, @available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)*/
|
||||||
extension FilePath {
|
extension FilePath {
|
||||||
/// Represents a root of a file path.
|
/// Represents a root of a file path.
|
||||||
///
|
///
|
||||||
@@ -73,7 +73,7 @@ extension FilePath {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// @available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
|
/*System 0.0.2, @available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)*/
|
||||||
extension FilePath.Component {
|
extension FilePath.Component {
|
||||||
|
|
||||||
/// Whether a component is a regular file or directory name, or a special
|
/// Whether a component is a regular file or directory name, or a special
|
||||||
|
|||||||
@@ -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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -9,7 +9,7 @@
|
|||||||
|
|
||||||
// MARK: - Platform string
|
// MARK: - Platform string
|
||||||
|
|
||||||
// @available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
|
/*System 0.0.2, @available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)*/
|
||||||
extension FilePath {
|
extension FilePath {
|
||||||
/// Creates a file path by copying bytes from a null-terminated platform
|
/// Creates a file path by copying bytes from a null-terminated platform
|
||||||
/// string.
|
/// string.
|
||||||
@@ -20,6 +20,49 @@ extension FilePath {
|
|||||||
self.init(_platformString: platformString)
|
self.init(_platformString: platformString)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Creates a file path by copying bytes from a null-terminated platform
|
||||||
|
/// string.
|
||||||
|
///
|
||||||
|
/// - Note It is a precondition that `platformString` must be null-terminated.
|
||||||
|
/// The absence of a null byte will trigger a runtime error.
|
||||||
|
///
|
||||||
|
/// - Parameter platformString: A null-terminated platform string.
|
||||||
|
@inlinable
|
||||||
|
@_alwaysEmitIntoClient
|
||||||
|
public init(platformString: [CInterop.PlatformChar]) {
|
||||||
|
guard let _ = platformString.firstIndex(of: 0) else {
|
||||||
|
fatalError(
|
||||||
|
"input of FilePath.init(platformString:) must be null-terminated"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
self = platformString.withUnsafeBufferPointer {
|
||||||
|
FilePath(platformString: $0.baseAddress!)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@inlinable
|
||||||
|
@_alwaysEmitIntoClient
|
||||||
|
@available(*, deprecated, message: "Use FilePath.init(_ scalar: Unicode.Scalar)")
|
||||||
|
public init(platformString: inout CInterop.PlatformChar) {
|
||||||
|
guard platformString == 0 else {
|
||||||
|
fatalError(
|
||||||
|
"input of FilePath.init(platformString:) must be null-terminated"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
self = FilePath()
|
||||||
|
}
|
||||||
|
|
||||||
|
@inlinable
|
||||||
|
@_alwaysEmitIntoClient
|
||||||
|
@available(*, deprecated, message: "Use FilePath(_: String) to create a path from a String")
|
||||||
|
public init(platformString: String) {
|
||||||
|
if let nullLoc = platformString.firstIndex(of: "\0") {
|
||||||
|
self = FilePath(String(platformString[..<nullLoc]))
|
||||||
|
} else {
|
||||||
|
self = FilePath(platformString)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Calls the given closure with a pointer to the contents of the file path,
|
/// Calls the given closure with a pointer to the contents of the file path,
|
||||||
/// represented as a null-terminated platform string.
|
/// represented as a null-terminated platform string.
|
||||||
///
|
///
|
||||||
@@ -45,7 +88,7 @@ extension FilePath {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// @available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
|
/*System 0.0.2, @available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)*/
|
||||||
extension FilePath.Component {
|
extension FilePath.Component {
|
||||||
/// Creates a file path component by copying bytes from a null-terminated
|
/// Creates a file path component by copying bytes from a null-terminated
|
||||||
/// platform string.
|
/// platform string.
|
||||||
@@ -60,6 +103,59 @@ extension FilePath.Component {
|
|||||||
self.init(_platformString: platformString)
|
self.init(_platformString: platformString)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Creates a file path component by copying bytes from a null-terminated
|
||||||
|
/// platform string. It is a precondition that a null byte indicates the end of
|
||||||
|
/// the string. The absence of a null byte will trigger a runtime error.
|
||||||
|
///
|
||||||
|
/// Returns `nil` if `platformString` is empty, is a root, or has more than
|
||||||
|
/// one component in it.
|
||||||
|
///
|
||||||
|
/// - Note It is a precondition that `platformString` must be null-terminated.
|
||||||
|
/// The absence of a null byte will trigger a runtime error.
|
||||||
|
///
|
||||||
|
/// - Parameter platformString: A null-terminated platform string.
|
||||||
|
@inlinable
|
||||||
|
@_alwaysEmitIntoClient
|
||||||
|
public init?(platformString: [CInterop.PlatformChar]) {
|
||||||
|
guard let _ = platformString.firstIndex(of: 0) else {
|
||||||
|
fatalError(
|
||||||
|
"input of FilePath.Component.init?(platformString:) must be null-terminated"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
guard let component = platformString.withUnsafeBufferPointer({
|
||||||
|
FilePath.Component(platformString: $0.baseAddress!)
|
||||||
|
}) else {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
self = component
|
||||||
|
}
|
||||||
|
|
||||||
|
@inlinable
|
||||||
|
@_alwaysEmitIntoClient
|
||||||
|
@available(*, deprecated, message: "Use FilePath.Component.init(_ scalar: Unicode.Scalar)")
|
||||||
|
public init?(platformString: inout CInterop.PlatformChar) {
|
||||||
|
guard platformString == 0 else {
|
||||||
|
fatalError(
|
||||||
|
"input of FilePath.Component.init?(platformString:) must be null-terminated"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
@inlinable
|
||||||
|
@_alwaysEmitIntoClient
|
||||||
|
@available(*, deprecated, message: "Use FilePath.Component.init(_: String)")
|
||||||
|
public init?(platformString: String) {
|
||||||
|
let string: String
|
||||||
|
if let nullLoc = platformString.firstIndex(of: "\0") {
|
||||||
|
string = String(platformString[..<nullLoc])
|
||||||
|
} else {
|
||||||
|
string = platformString
|
||||||
|
}
|
||||||
|
guard let component = FilePath.Component(string) else { return nil }
|
||||||
|
self = component
|
||||||
|
}
|
||||||
|
|
||||||
/// Calls the given closure with a pointer to the contents of the file path
|
/// Calls the given closure with a pointer to the contents of the file path
|
||||||
/// component, represented as a null-terminated platform string.
|
/// component, represented as a null-terminated platform string.
|
||||||
///
|
///
|
||||||
@@ -82,7 +178,7 @@ extension FilePath.Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// @available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
|
/*System 0.0.2, @available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)*/
|
||||||
extension FilePath.Root {
|
extension FilePath.Root {
|
||||||
/// Creates a file path root by copying bytes from a null-terminated platform
|
/// Creates a file path root by copying bytes from a null-terminated platform
|
||||||
/// string.
|
/// string.
|
||||||
@@ -96,6 +192,58 @@ extension FilePath.Root {
|
|||||||
self.init(_platformString: platformString)
|
self.init(_platformString: platformString)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Creates a file path root by copying bytes from a null-terminated platform
|
||||||
|
/// string. It is a precondition that a null byte indicates the end of
|
||||||
|
/// the string. The absence of a null byte will trigger a runtime error.
|
||||||
|
///
|
||||||
|
/// Returns `nil` if `platformString` is empty or is not a root.
|
||||||
|
///
|
||||||
|
/// - Note It is a precondition that `platformString` must be null-terminated.
|
||||||
|
/// The absence of a null byte will trigger a runtime error.
|
||||||
|
///
|
||||||
|
/// - Parameter platformString: A null-terminated platform string.
|
||||||
|
@inlinable
|
||||||
|
@_alwaysEmitIntoClient
|
||||||
|
public init?(platformString: [CInterop.PlatformChar]) {
|
||||||
|
guard let _ = platformString.firstIndex(of: 0) else {
|
||||||
|
fatalError(
|
||||||
|
"input of FilePath.Root.init?(platformString:) must be null-terminated"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
guard let component = platformString.withUnsafeBufferPointer({
|
||||||
|
FilePath.Root(platformString: $0.baseAddress!)
|
||||||
|
}) else {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
self = component
|
||||||
|
}
|
||||||
|
|
||||||
|
@inlinable
|
||||||
|
@_alwaysEmitIntoClient
|
||||||
|
@available(*, deprecated, message: "Use FilePath.Root.init(_ scalar: Unicode.Scalar)")
|
||||||
|
public init?(platformString: inout CInterop.PlatformChar) {
|
||||||
|
guard platformString == 0 else {
|
||||||
|
fatalError(
|
||||||
|
"input of FilePath.Root.init?(platformString:) must be null-terminated"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
@inlinable
|
||||||
|
@_alwaysEmitIntoClient
|
||||||
|
@available(*, deprecated, message: "Use FilePath.Root.init(_: String)")
|
||||||
|
public init?(platformString: String) {
|
||||||
|
let string: String
|
||||||
|
if let nullLoc = platformString.firstIndex(of: "\0") {
|
||||||
|
string = String(platformString[..<nullLoc])
|
||||||
|
} else {
|
||||||
|
string = platformString
|
||||||
|
}
|
||||||
|
guard let root = FilePath.Root(string) else { return nil }
|
||||||
|
self = root
|
||||||
|
}
|
||||||
|
|
||||||
/// Calls the given closure with a pointer to the contents of the file path
|
/// Calls the given closure with a pointer to the contents of the file path
|
||||||
/// root, represented as a null-terminated platform string.
|
/// root, represented as a null-terminated platform string.
|
||||||
///
|
///
|
||||||
@@ -120,7 +268,7 @@ extension FilePath.Root {
|
|||||||
|
|
||||||
// MARK: - String literals
|
// MARK: - String literals
|
||||||
|
|
||||||
// @available(macOS 10.16, 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: ExpressibleByStringLiteral {
|
extension FilePath: ExpressibleByStringLiteral {
|
||||||
/// Creates a file path from a string literal.
|
/// Creates a file path from a string literal.
|
||||||
///
|
///
|
||||||
@@ -139,7 +287,7 @@ extension FilePath: ExpressibleByStringLiteral {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// @available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
|
/*System 0.0.2, @available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)*/
|
||||||
extension FilePath.Component: ExpressibleByStringLiteral {
|
extension FilePath.Component: ExpressibleByStringLiteral {
|
||||||
/// Create a file path component from a string literal.
|
/// Create a file path component from a string literal.
|
||||||
///
|
///
|
||||||
@@ -148,7 +296,7 @@ extension FilePath.Component: ExpressibleByStringLiteral {
|
|||||||
public init(stringLiteral: String) {
|
public init(stringLiteral: String) {
|
||||||
guard let s = FilePath.Component(stringLiteral) else {
|
guard let s = FilePath.Component(stringLiteral) else {
|
||||||
// TODO: static assert
|
// TODO: static assert
|
||||||
preconditionFailure("""
|
fatalError("""
|
||||||
FilePath.Component must be created from exactly one non-root component
|
FilePath.Component must be created from exactly one non-root component
|
||||||
""")
|
""")
|
||||||
}
|
}
|
||||||
@@ -164,7 +312,7 @@ extension FilePath.Component: ExpressibleByStringLiteral {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// @available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
|
/*System 0.0.2, @available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)*/
|
||||||
extension FilePath.Root: ExpressibleByStringLiteral {
|
extension FilePath.Root: ExpressibleByStringLiteral {
|
||||||
/// Create a file path root from a string literal.
|
/// Create a file path root from a string literal.
|
||||||
///
|
///
|
||||||
@@ -172,7 +320,7 @@ extension FilePath.Root: ExpressibleByStringLiteral {
|
|||||||
public init(stringLiteral: String) {
|
public init(stringLiteral: String) {
|
||||||
guard let s = FilePath.Root(stringLiteral) else {
|
guard let s = FilePath.Root(stringLiteral) else {
|
||||||
// TODO: static assert
|
// TODO: static assert
|
||||||
preconditionFailure("""
|
fatalError("""
|
||||||
FilePath.Root must be created from a root
|
FilePath.Root must be created from a root
|
||||||
""")
|
""")
|
||||||
}
|
}
|
||||||
@@ -189,7 +337,7 @@ extension FilePath.Root: ExpressibleByStringLiteral {
|
|||||||
|
|
||||||
// MARK: - Printing and dumping
|
// MARK: - Printing and dumping
|
||||||
|
|
||||||
// @available(macOS 10.16, 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: CustomStringConvertible, CustomDebugStringConvertible {
|
extension FilePath: CustomStringConvertible, CustomDebugStringConvertible {
|
||||||
/// A textual representation of the file path.
|
/// A textual representation of the file path.
|
||||||
///
|
///
|
||||||
@@ -205,7 +353,7 @@ extension FilePath: CustomStringConvertible, CustomDebugStringConvertible {
|
|||||||
public var debugDescription: String { description.debugDescription }
|
public var debugDescription: String { description.debugDescription }
|
||||||
}
|
}
|
||||||
|
|
||||||
// @available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
|
/*System 0.0.2, @available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)*/
|
||||||
extension FilePath.Component: CustomStringConvertible, CustomDebugStringConvertible {
|
extension FilePath.Component: CustomStringConvertible, CustomDebugStringConvertible {
|
||||||
|
|
||||||
/// A textual representation of the path component.
|
/// A textual representation of the path component.
|
||||||
@@ -222,7 +370,7 @@ extension FilePath.Component: CustomStringConvertible, CustomDebugStringConverti
|
|||||||
public var debugDescription: String { description.debugDescription }
|
public var debugDescription: String { description.debugDescription }
|
||||||
}
|
}
|
||||||
|
|
||||||
// @available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
|
/*System 0.0.2, @available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)*/
|
||||||
extension FilePath.Root: CustomStringConvertible, CustomDebugStringConvertible {
|
extension FilePath.Root: CustomStringConvertible, CustomDebugStringConvertible {
|
||||||
|
|
||||||
/// A textual representation of the path root.
|
/// A textual representation of the path root.
|
||||||
@@ -242,7 +390,7 @@ extension FilePath.Root: CustomStringConvertible, CustomDebugStringConvertible {
|
|||||||
// MARK: - Convenience helpers
|
// MARK: - Convenience helpers
|
||||||
|
|
||||||
// Convenience helpers
|
// Convenience helpers
|
||||||
// @available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
|
/*System 0.0.2, @available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)*/
|
||||||
extension FilePath {
|
extension FilePath {
|
||||||
/// Creates a string by interpreting the path’s content as UTF-8 on Unix
|
/// Creates a string by interpreting the path’s content as UTF-8 on Unix
|
||||||
/// and UTF-16 on Windows.
|
/// and UTF-16 on Windows.
|
||||||
@@ -253,7 +401,7 @@ extension FilePath {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// @available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
|
/*System 0.0.2, @available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)*/
|
||||||
extension FilePath.Component {
|
extension FilePath.Component {
|
||||||
/// Creates a string by interpreting the component’s content as UTF-8 on Unix
|
/// Creates a string by interpreting the component’s content as UTF-8 on Unix
|
||||||
/// and UTF-16 on Windows.
|
/// and UTF-16 on Windows.
|
||||||
@@ -264,7 +412,7 @@ extension FilePath.Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// @available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
|
/*System 0.0.2, @available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)*/
|
||||||
extension FilePath.Root {
|
extension FilePath.Root {
|
||||||
/// On Unix, this returns `"/"`.
|
/// On Unix, this returns `"/"`.
|
||||||
///
|
///
|
||||||
@@ -278,7 +426,7 @@ extension FilePath.Root {
|
|||||||
|
|
||||||
// MARK: - Decoding and validating
|
// MARK: - Decoding and validating
|
||||||
|
|
||||||
// @available(macOS 10.16, 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 String {
|
extension String {
|
||||||
/// Creates a string by interpreting the file path's content as UTF-8 on Unix
|
/// Creates a string by interpreting the file path's content as UTF-8 on Unix
|
||||||
/// and UTF-16 on Windows.
|
/// and UTF-16 on Windows.
|
||||||
@@ -308,7 +456,7 @@ extension String {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// @available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
|
/*System 0.0.2, @available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)*/
|
||||||
extension String {
|
extension String {
|
||||||
/// Creates a string by interpreting the path component's content as UTF-8 on
|
/// Creates a string by interpreting the path component's content as UTF-8 on
|
||||||
/// Unix and UTF-16 on Windows.
|
/// Unix and UTF-16 on Windows.
|
||||||
@@ -338,7 +486,7 @@ extension String {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// @available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
|
/*System 0.0.2, @available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)*/
|
||||||
extension String {
|
extension String {
|
||||||
/// On Unix, creates the string `"/"`
|
/// On Unix, creates the string `"/"`
|
||||||
///
|
///
|
||||||
@@ -391,7 +539,7 @@ extension String {
|
|||||||
|
|
||||||
// MARK: - Deprecations
|
// MARK: - Deprecations
|
||||||
|
|
||||||
// @available(macOS 10.16, 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 String {
|
extension String {
|
||||||
@available(*, deprecated, renamed: "init(decoding:)")
|
@available(*, deprecated, renamed: "init(decoding:)")
|
||||||
public init(_ path: FilePath) { self.init(decoding: path) }
|
public init(_ path: FilePath) { self.init(decoding: path) }
|
||||||
@@ -401,14 +549,30 @@ extension String {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if !os(Windows)
|
#if !os(Windows)
|
||||||
// @available(macOS 10.16, 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 {
|
extension FilePath {
|
||||||
/// For backwards compatibility only. This initializer is equivalent to
|
/// For backwards compatibility only. This initializer is equivalent to
|
||||||
/// the preferred `FilePath(platformString:)`.
|
/// the preferred `FilePath(platformString:)`.
|
||||||
|
@available(*, deprecated, renamed: "init(platformString:)")
|
||||||
public init(cString: UnsafePointer<CChar>) {
|
public init(cString: UnsafePointer<CChar>) {
|
||||||
self.init(platformString: cString)
|
self.init(platformString: cString)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@available(*, deprecated, renamed: "init(platformString:)")
|
||||||
|
public init(cString: [CChar]) {
|
||||||
|
self.init(platformString: cString)
|
||||||
|
}
|
||||||
|
|
||||||
|
@available(*, deprecated, renamed: "init(platformString:)")
|
||||||
|
public init(cString: inout CChar) {
|
||||||
|
self.init(platformString: &cString)
|
||||||
|
}
|
||||||
|
|
||||||
|
@available(*, deprecated, renamed: "init(platformString:)")
|
||||||
|
public init(cString: String) {
|
||||||
|
self.init(platformString: cString)
|
||||||
|
}
|
||||||
|
|
||||||
/// For backwards compatibility only. This function is equivalent to
|
/// For backwards compatibility only. This function is equivalent to
|
||||||
/// the preferred `withPlatformString`.
|
/// the preferred `withPlatformString`.
|
||||||
public func withCString<Result>(
|
public func withCString<Result>(
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
|
|
||||||
// MARK: - Query API
|
// MARK: - Query API
|
||||||
|
|
||||||
// @available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
|
/*System 0.0.2, @available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)*/
|
||||||
extension FilePath {
|
extension FilePath {
|
||||||
/// Returns true if this path uniquely identifies the location of
|
/// Returns true if this path uniquely identifies the location of
|
||||||
/// a file without reference to an additional starting location.
|
/// a file without reference to an additional starting location.
|
||||||
@@ -64,9 +64,8 @@ extension FilePath {
|
|||||||
/// path.starts(with: "/usr/bin/ls///") // true
|
/// path.starts(with: "/usr/bin/ls///") // true
|
||||||
/// path.starts(with: "/us") // false
|
/// path.starts(with: "/us") // false
|
||||||
///
|
///
|
||||||
/// TODO(Windows docs): examples with roots, such as whether `\foo\bar`
|
// TODO(Windows docs): examples with roots, such as whether `\foo\bar`
|
||||||
/// starts with `C:\foo`
|
// starts with `C:\foo`
|
||||||
///
|
|
||||||
public func starts(with other: FilePath) -> Bool {
|
public func starts(with other: FilePath) -> Bool {
|
||||||
guard !other.isEmpty else { return true }
|
guard !other.isEmpty else { return true }
|
||||||
return self.root == other.root && components.starts(
|
return self.root == other.root && components.starts(
|
||||||
@@ -85,9 +84,8 @@ extension FilePath {
|
|||||||
/// path.ends(with: "/usr/bin/ls///") // true
|
/// path.ends(with: "/usr/bin/ls///") // true
|
||||||
/// path.ends(with: "/ls") // false
|
/// path.ends(with: "/ls") // false
|
||||||
///
|
///
|
||||||
/// TODO(Windows docs): examples with roots, such as whether `C:\foo\bar`
|
// TODO(Windows docs): examples with roots, such as whether `C:\foo\bar`
|
||||||
/// ends with `C:bar`
|
// ends with `C:bar`
|
||||||
///
|
|
||||||
public func ends(with other: FilePath) -> Bool {
|
public func ends(with other: FilePath) -> Bool {
|
||||||
if other.root != nil {
|
if other.root != nil {
|
||||||
// TODO: anything tricky here for Windows?
|
// TODO: anything tricky here for Windows?
|
||||||
@@ -103,7 +101,7 @@ extension FilePath {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - Decompose a path
|
// MARK: - Decompose a path
|
||||||
// @available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
|
/*System 0.0.2, @available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)*/
|
||||||
extension FilePath {
|
extension FilePath {
|
||||||
/// Returns the root of a path if there is one, otherwise `nil`.
|
/// Returns the root of a path if there is one, otherwise `nil`.
|
||||||
///
|
///
|
||||||
@@ -188,7 +186,7 @@ extension FilePath {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// @available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
|
/*System 0.0.2, @available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)*/
|
||||||
extension FilePath {
|
extension FilePath {
|
||||||
/// Returns the final component of the path.
|
/// Returns the final component of the path.
|
||||||
/// Returns `nil` if the path is empty or only contains a root.
|
/// Returns `nil` if the path is empty or only contains a root.
|
||||||
@@ -260,7 +258,7 @@ extension FilePath {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// @available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
|
/*System 0.0.2, @available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)*/
|
||||||
extension FilePath.Component {
|
extension FilePath.Component {
|
||||||
/// The extension of this file or directory component.
|
/// The extension of this file or directory component.
|
||||||
///
|
///
|
||||||
@@ -293,7 +291,7 @@ extension FilePath.Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// @available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
|
/*System 0.0.2, @available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)*/
|
||||||
extension FilePath {
|
extension FilePath {
|
||||||
|
|
||||||
/// The extension of the file or directory last component.
|
/// The extension of the file or directory last component.
|
||||||
@@ -360,7 +358,7 @@ extension FilePath {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// @available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
|
/*System 0.0.2, @available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)*/
|
||||||
extension FilePath {
|
extension FilePath {
|
||||||
/// Whether the path is in lexical-normal form, that is `.` and `..`
|
/// Whether the path is in lexical-normal form, that is `.` and `..`
|
||||||
/// components have been collapsed lexically (i.e. without following
|
/// components have been collapsed lexically (i.e. without following
|
||||||
@@ -441,10 +439,10 @@ extension FilePath {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Modification and concatenation API
|
// Modification and concatenation API
|
||||||
// @available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
|
/*System 0.0.2, @available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)*/
|
||||||
extension FilePath {
|
extension FilePath {
|
||||||
/// If `prefix` is a prefix of `self`, removes it and returns `true`.
|
/// If `prefix` is a prefix of `self`, removes it and returns `true`.
|
||||||
/// Otherwise returns `false`.
|
/// Otherwise returns `false`.
|
||||||
///
|
///
|
||||||
/// Example:
|
/// Example:
|
||||||
///
|
///
|
||||||
@@ -453,8 +451,7 @@ extension FilePath {
|
|||||||
/// path.removePrefix("/us") // false
|
/// path.removePrefix("/us") // false
|
||||||
/// path.removePrefix("/usr/local") // true, path is "bin"
|
/// path.removePrefix("/usr/local") // true, path is "bin"
|
||||||
///
|
///
|
||||||
/// TODO(Windows docs): example with roots
|
// TODO(Windows docs): example with roots
|
||||||
///
|
|
||||||
public mutating func removePrefix(_ prefix: FilePath) -> Bool {
|
public mutating func removePrefix(_ prefix: FilePath) -> Bool {
|
||||||
defer { _invariantCheck() }
|
defer { _invariantCheck() }
|
||||||
// FIXME: Should Windows have more nuanced semantics?
|
// FIXME: Should Windows have more nuanced semantics?
|
||||||
@@ -476,8 +473,7 @@ extension FilePath {
|
|||||||
/// }
|
/// }
|
||||||
/// // path is "/tmp/foo/bar/../baz"
|
/// // path is "/tmp/foo/bar/../baz"
|
||||||
///
|
///
|
||||||
/// TODO(Windows docs): example with roots
|
// TODO(Windows docs): example with roots
|
||||||
///
|
|
||||||
public mutating func append(_ component: __owned FilePath.Component) {
|
public mutating func append(_ component: __owned FilePath.Component) {
|
||||||
defer { _invariantCheck() }
|
defer { _invariantCheck() }
|
||||||
_append(unchecked: component._slice)
|
_append(unchecked: component._slice)
|
||||||
@@ -492,8 +488,7 @@ extension FilePath {
|
|||||||
/// let otherPath: FilePath = "/bin/ls"
|
/// let otherPath: FilePath = "/bin/ls"
|
||||||
/// path.append(otherPath.components) // path is "/usr/local/bin/ls"
|
/// path.append(otherPath.components) // path is "/usr/local/bin/ls"
|
||||||
///
|
///
|
||||||
/// TODO(Windows docs): example with roots
|
// TODO(Windows docs): example with roots
|
||||||
///
|
|
||||||
public mutating func append<C: Collection>(
|
public mutating func append<C: Collection>(
|
||||||
_ components: __owned C
|
_ components: __owned C
|
||||||
) where C.Element == FilePath.Component {
|
) where C.Element == FilePath.Component {
|
||||||
@@ -508,14 +503,14 @@ extension FilePath {
|
|||||||
/// A leading separator is spurious if `self` is non-empty.
|
/// A leading separator is spurious if `self` is non-empty.
|
||||||
///
|
///
|
||||||
/// Example:
|
/// Example:
|
||||||
/// var path: FilePath = ""
|
|
||||||
/// path.append("/var/www/website") // "/var/www/website"
|
|
||||||
/// path.append("static/assets") // "/var/www/website/static/assets"
|
|
||||||
/// path.append("/main.css") // "/var/www/website/static/assets/main.css"
|
|
||||||
///
|
///
|
||||||
/// TODO(Windows docs): example with roots, should we rephrase this "spurious
|
/// var path: FilePath = ""
|
||||||
/// roots"?
|
/// path.append("/var/www/website") // "/var/www/website"
|
||||||
|
/// path.append("static/assets") // "/var/www/website/static/assets"
|
||||||
|
/// path.append("/main.css") // "/var/www/website/static/assets/main.css"
|
||||||
///
|
///
|
||||||
|
// TODO(Windows docs): example with roots, should we rephrase this "spurious
|
||||||
|
// roots"?
|
||||||
public mutating func append(_ other: __owned String) {
|
public mutating func append(_ other: __owned String) {
|
||||||
defer { _invariantCheck() }
|
defer { _invariantCheck() }
|
||||||
guard !other.utf8.isEmpty else { return }
|
guard !other.utf8.isEmpty else { return }
|
||||||
@@ -529,8 +524,7 @@ extension FilePath {
|
|||||||
|
|
||||||
/// Non-mutating version of `append(_:Component)`.
|
/// Non-mutating version of `append(_:Component)`.
|
||||||
///
|
///
|
||||||
/// TODO(Windows docs): example with roots
|
// TODO(Windows docs): example with roots
|
||||||
///
|
|
||||||
public __consuming func appending(_ other: __owned Component) -> FilePath {
|
public __consuming func appending(_ other: __owned Component) -> FilePath {
|
||||||
var copy = self
|
var copy = self
|
||||||
copy.append(other)
|
copy.append(other)
|
||||||
@@ -539,8 +533,7 @@ extension FilePath {
|
|||||||
|
|
||||||
/// Non-mutating version of `append(_:C)`.
|
/// Non-mutating version of `append(_:C)`.
|
||||||
///
|
///
|
||||||
/// TODO(Windows docs): example with roots
|
// TODO(Windows docs): example with roots
|
||||||
///
|
|
||||||
public __consuming func appending<C: Collection>(
|
public __consuming func appending<C: Collection>(
|
||||||
_ components: __owned C
|
_ components: __owned C
|
||||||
) -> FilePath where C.Element == FilePath.Component {
|
) -> FilePath where C.Element == FilePath.Component {
|
||||||
@@ -551,8 +544,7 @@ extension FilePath {
|
|||||||
|
|
||||||
/// Non-mutating version of `append(_:String)`.
|
/// Non-mutating version of `append(_:String)`.
|
||||||
///
|
///
|
||||||
/// TODO(Windows docs): example with roots
|
// TODO(Windows docs): example with roots
|
||||||
///
|
|
||||||
public __consuming func appending(_ other: __owned String) -> FilePath {
|
public __consuming func appending(_ other: __owned String) -> FilePath {
|
||||||
var copy = self
|
var copy = self
|
||||||
copy.append(other)
|
copy.append(other)
|
||||||
@@ -573,23 +565,21 @@ extension FilePath {
|
|||||||
/// path.push("dir/file.txt") // path is "/tmp/dir/file.txt"
|
/// path.push("dir/file.txt") // path is "/tmp/dir/file.txt"
|
||||||
/// path.push("/bin") // path is "/bin"
|
/// path.push("/bin") // path is "/bin"
|
||||||
///
|
///
|
||||||
/// TODO(Windows docs): examples and docs with roots, update/generalize doc
|
// TODO(Windows docs): examples and docs with roots, update/generalize doc
|
||||||
/// comment
|
// comment
|
||||||
///
|
|
||||||
public mutating func push(_ other: __owned FilePath) {
|
public mutating func push(_ other: __owned FilePath) {
|
||||||
defer { _invariantCheck() }
|
defer { _invariantCheck() }
|
||||||
guard other.root == nil else {
|
guard other.root == nil else {
|
||||||
self = other
|
self = other
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
/// FIXME: Windows drive-relative roots, etc?
|
// FIXME: Windows drive-relative roots, etc?
|
||||||
_append(unchecked: other._storage[...])
|
_append(unchecked: other._storage[...])
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Non-mutating version of `push()`
|
/// Non-mutating version of `push()`.
|
||||||
///
|
|
||||||
/// TODO(Windows docs): examples and docs with roots
|
|
||||||
///
|
///
|
||||||
|
// TODO(Windows docs): examples and docs with roots
|
||||||
public __consuming func pushing(_ other: __owned FilePath) -> FilePath {
|
public __consuming func pushing(_ other: __owned FilePath) -> FilePath {
|
||||||
var copy = self
|
var copy = self
|
||||||
copy.push(other)
|
copy.push(other)
|
||||||
@@ -611,7 +601,7 @@ extension FilePath {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// MARK - Renamed
|
// MARK - Renamed
|
||||||
// @available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
|
/*System 0.0.2, @available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)*/
|
||||||
extension FilePath {
|
extension FilePath {
|
||||||
@available(*, unavailable, renamed: "removingLastComponent()")
|
@available(*, unavailable, renamed: "removingLastComponent()")
|
||||||
public var dirname: FilePath { removingLastComponent() }
|
public var dirname: FilePath { removingLastComponent() }
|
||||||
|
|||||||
@@ -156,7 +156,7 @@ internal struct WindowsRootInfo {
|
|||||||
/// * Device disk: `\\.\C:\`, `\\?\C:\`
|
/// * Device disk: `\\.\C:\`, `\\?\C:\`
|
||||||
/// * UNC: `\\server\e:\`, `\\?\UNC\server\e:\`
|
/// * UNC: `\\server\e:\`, `\\?\UNC\server\e:\`
|
||||||
///
|
///
|
||||||
/// TODO: NT paths? Admin paths using `$`?
|
// TODO: NT paths? Admin paths using `$`?
|
||||||
case drive(Character)
|
case drive(Character)
|
||||||
|
|
||||||
/// A volume with a GUID in a non-traditional path
|
/// A volume with a GUID in a non-traditional path
|
||||||
@@ -164,7 +164,7 @@ internal struct WindowsRootInfo {
|
|||||||
/// * UNC: `\\host\Volume{0000-...}\`, `\\.\UNC\host\Volume{0000-...}\`
|
/// * UNC: `\\host\Volume{0000-...}\`, `\\.\UNC\host\Volume{0000-...}\`
|
||||||
/// * Device roots: `\\.\Volume{0000-...}\`, `\\?\Volume{000-...}\`
|
/// * Device roots: `\\.\Volume{0000-...}\`, `\\?\Volume{000-...}\`
|
||||||
///
|
///
|
||||||
/// TODO: GUID type?
|
// TODO: GUID type?
|
||||||
case guid(String)
|
case guid(String)
|
||||||
|
|
||||||
// TODO: Legacy DOS devices, such as COM1?
|
// TODO: Legacy DOS devices, such as COM1?
|
||||||
|
|||||||
@@ -17,7 +17,7 @@
|
|||||||
/// let perms = FilePermissions(rawValue: 0o644)
|
/// let perms = FilePermissions(rawValue: 0o644)
|
||||||
/// perms == [.ownerReadWrite, .groupRead, .otherRead] // true
|
/// perms == [.ownerReadWrite, .groupRead, .otherRead] // true
|
||||||
@frozen
|
@frozen
|
||||||
// @available(macOS 10.16, 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, *)*/
|
||||||
public struct FilePermissions: OptionSet, Hashable, Codable {
|
public struct FilePermissions: OptionSet, Hashable, Codable {
|
||||||
/// The raw C file permissions.
|
/// The raw C file permissions.
|
||||||
@_alwaysEmitIntoClient
|
@_alwaysEmitIntoClient
|
||||||
@@ -135,7 +135,7 @@ public struct FilePermissions: OptionSet, Hashable, Codable {
|
|||||||
public static var saveText: FilePermissions { FilePermissions(0o1000) }
|
public static var saveText: FilePermissions { FilePermissions(0o1000) }
|
||||||
}
|
}
|
||||||
|
|
||||||
// @available(macOS 10.16, 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 FilePermissions
|
extension FilePermissions
|
||||||
: CustomStringConvertible, CustomDebugStringConvertible
|
: CustomStringConvertible, CustomDebugStringConvertible
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -10,24 +10,27 @@
|
|||||||
// MARK: - Public typealiases
|
// MARK: - Public typealiases
|
||||||
|
|
||||||
/// The C `mode_t` type.
|
/// The C `mode_t` type.
|
||||||
// @available(macOS 10.16, 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, *)*/
|
||||||
@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)
|
|
||||||
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
|
||||||
|
|
||||||
/// A namespace for C and platform types
|
/// A namespace for C and platform types
|
||||||
// @available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
|
/*System 0.0.2, @available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)*/
|
||||||
public enum CInterop {
|
public enum CInterop {
|
||||||
#if os(Windows)
|
#if os(Windows)
|
||||||
public typealias Mode = CInt
|
public typealias Mode = CInt
|
||||||
|
|||||||
@@ -11,20 +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 CSystem
|
|
||||||
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
|
||||||
@@ -270,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
|
||||||
@@ -311,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 }
|
||||||
|
|
||||||
@@ -334,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 }
|
||||||
|
|
||||||
@@ -356,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 }
|
||||||
|
|
||||||
@@ -384,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
|
||||||
@@ -418,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
|
||||||
@@ -431,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 }
|
||||||
|
|
||||||
@@ -451,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 }
|
||||||
@@ -462,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 }
|
||||||
|
|
||||||
@@ -488,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
|
||||||
@@ -498,12 +504,11 @@ internal var _O_EVTONLY: CInt { O_EVTONLY }
|
|||||||
@_alwaysEmitIntoClient
|
@_alwaysEmitIntoClient
|
||||||
internal var _O_NOCTTY: CInt { O_NOCTTY }
|
internal var _O_NOCTTY: CInt { O_NOCTTY }
|
||||||
|
|
||||||
// TODO: API?
|
|
||||||
@_alwaysEmitIntoClient
|
@_alwaysEmitIntoClient
|
||||||
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
|
||||||
@@ -522,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)
|
|
||||||
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
|
||||||
|
|||||||
@@ -146,7 +146,7 @@ private func originalSyscallName(_ function: String) -> String {
|
|||||||
|
|
||||||
private func mockImpl(
|
private func mockImpl(
|
||||||
name: String,
|
name: String,
|
||||||
path: UnsafePointer<CChar>?,
|
path: UnsafePointer<CInterop.PlatformChar>?,
|
||||||
_ args: [AnyHashable]
|
_ args: [AnyHashable]
|
||||||
) -> CInt {
|
) -> CInt {
|
||||||
precondition(mockingEnabled)
|
precondition(mockingEnabled)
|
||||||
@@ -177,18 +177,18 @@ private func mockImpl(
|
|||||||
}
|
}
|
||||||
|
|
||||||
internal func _mock(
|
internal func _mock(
|
||||||
name: String = #function, path: UnsafePointer<CChar>? = nil, _ args: AnyHashable...
|
name: String = #function, path: UnsafePointer<CInterop.PlatformChar>? = nil, _ args: AnyHashable...
|
||||||
) -> CInt {
|
) -> CInt {
|
||||||
return mockImpl(name: name, path: path, args)
|
return mockImpl(name: name, path: path, args)
|
||||||
}
|
}
|
||||||
internal func _mockInt(
|
internal func _mockInt(
|
||||||
name: String = #function, path: UnsafePointer<CChar>? = nil, _ args: AnyHashable...
|
name: String = #function, path: UnsafePointer<CInterop.PlatformChar>? = nil, _ args: AnyHashable...
|
||||||
) -> Int {
|
) -> Int {
|
||||||
Int(mockImpl(name: name, path: path, args))
|
Int(mockImpl(name: name, path: path, args))
|
||||||
}
|
}
|
||||||
|
|
||||||
internal func _mockOffT(
|
internal func _mockOffT(
|
||||||
name: String = #function, path: UnsafePointer<CChar>? = nil, _ args: AnyHashable...
|
name: String = #function, path: UnsafePointer<CInterop.PlatformChar>? = nil, _ args: AnyHashable...
|
||||||
) -> _COffT {
|
) -> _COffT {
|
||||||
_COffT(mockImpl(name: name, path: path, args))
|
_COffT(mockImpl(name: name, path: path, args))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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 {
|
||||||
@@ -115,3 +133,21 @@ internal func system_dup2(_ fd: Int32, _ fd2: Int32) -> Int32 {
|
|||||||
#endif
|
#endif
|
||||||
return dup2(fd, fd2)
|
return dup2(fd, fd2)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !os(Windows)
|
||||||
|
internal func system_pipe(_ fds: UnsafeMutablePointer<Int32>) -> CInt {
|
||||||
|
#if ENABLE_MOCKING
|
||||||
|
if mockingEnabled { return _mock(fds) }
|
||||||
|
#endif
|
||||||
|
return pipe(fds)
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if !os(Windows)
|
||||||
|
internal func system_ftruncate(_ fd: Int32, _ length: off_t) -> Int32 {
|
||||||
|
#if ENABLE_MOCKING
|
||||||
|
if mockingEnabled { return _mock(fd, length) }
|
||||||
|
#endif
|
||||||
|
return ftruncate(fd, length)
|
||||||
|
}
|
||||||
|
#endif
|
||||||
@@ -7,7 +7,7 @@
|
|||||||
See https://swift.org/LICENSE.txt for license information
|
See https://swift.org/LICENSE.txt for license information
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// @available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
|
/*System 0.0.2, @available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)*/
|
||||||
extension String {
|
extension String {
|
||||||
/// Creates a string by interpreting the null-terminated platform string as
|
/// Creates a string by interpreting the null-terminated platform string as
|
||||||
/// UTF-8 on Unix and UTF-16 on Windows.
|
/// UTF-8 on Unix and UTF-16 on Windows.
|
||||||
@@ -20,10 +20,61 @@ 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)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Creates a string by interpreting the null-terminated platform string as
|
||||||
|
/// UTF-8 on Unix and UTF-16 on Windows.
|
||||||
|
///
|
||||||
|
/// - Parameter platformString: The null-terminated platform string to be
|
||||||
|
/// interpreted as `CInterop.PlatformUnicodeEncoding`.
|
||||||
|
///
|
||||||
|
/// - Note It is a precondition that `platformString` must be null-terminated.
|
||||||
|
/// The absence of a null byte will trigger a runtime error.
|
||||||
|
///
|
||||||
|
/// If the content of the platform string isn't well-formed Unicode,
|
||||||
|
/// this initializer replaces invalid bytes with U+FFFD.
|
||||||
|
/// 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
|
||||||
|
/// from the original platform string.
|
||||||
|
@inlinable
|
||||||
|
@_alwaysEmitIntoClient
|
||||||
|
public init(platformString: [CInterop.PlatformChar]) {
|
||||||
|
guard let _ = platformString.firstIndex(of: 0) else {
|
||||||
|
fatalError(
|
||||||
|
"input of String.init(platformString:) must be null-terminated"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
self = platformString.withUnsafeBufferPointer {
|
||||||
|
String(platformString: $0.baseAddress!)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@inlinable
|
||||||
|
@_alwaysEmitIntoClient
|
||||||
|
@available(*, deprecated, message: "Use String.init(_ scalar: Unicode.Scalar)")
|
||||||
|
public init(platformString: inout CInterop.PlatformChar) {
|
||||||
|
guard platformString == 0 else {
|
||||||
|
fatalError(
|
||||||
|
"input of String.init(platformString:) must be null-terminated"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
self = ""
|
||||||
|
}
|
||||||
|
|
||||||
|
@inlinable
|
||||||
|
@_alwaysEmitIntoClient
|
||||||
|
@available(*, deprecated, message: "Use a copy of the String argument")
|
||||||
|
public init(platformString: String) {
|
||||||
|
if let nullLoc = platformString.firstIndex(of: "\0") {
|
||||||
|
self = String(platformString[..<nullLoc])
|
||||||
|
} else {
|
||||||
|
self = platformString
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Creates a string by interpreting the null-terminated platform string as
|
/// Creates a string by interpreting the null-terminated platform string as
|
||||||
/// UTF-8 on Unix and UTF-16 on Windows.
|
/// UTF-8 on Unix and UTF-16 on Windows.
|
||||||
///
|
///
|
||||||
@@ -38,6 +89,62 @@ extension String {
|
|||||||
self.init(_platformString: platformString)
|
self.init(_platformString: platformString)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Creates a string by interpreting the null-terminated platform string as
|
||||||
|
/// UTF-8 on Unix and UTF-16 on Windows.
|
||||||
|
///
|
||||||
|
/// - Parameter platformString: The null-terminated platform string to be
|
||||||
|
/// interpreted as `CInterop.PlatformUnicodeEncoding`.
|
||||||
|
///
|
||||||
|
/// - Note It is a precondition that `platformString` must be null-terminated.
|
||||||
|
/// The absence of a null byte will trigger a runtime error.
|
||||||
|
///
|
||||||
|
/// If the contents of the platform string isn't well-formed Unicode,
|
||||||
|
/// this initializer returns `nil`.
|
||||||
|
@inlinable
|
||||||
|
@_alwaysEmitIntoClient
|
||||||
|
public init?(
|
||||||
|
validatingPlatformString platformString: [CInterop.PlatformChar]
|
||||||
|
) {
|
||||||
|
guard let _ = platformString.firstIndex(of: 0) else {
|
||||||
|
fatalError(
|
||||||
|
"input of String.init(validatingPlatformString:) must be null-terminated"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
guard let string = platformString.withUnsafeBufferPointer({
|
||||||
|
String(validatingPlatformString: $0.baseAddress!)
|
||||||
|
}) else {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
self = string
|
||||||
|
}
|
||||||
|
|
||||||
|
@inlinable
|
||||||
|
@_alwaysEmitIntoClient
|
||||||
|
@available(*, deprecated, message: "Use String(_ scalar: Unicode.Scalar)")
|
||||||
|
public init?(
|
||||||
|
validatingPlatformString platformString: inout CInterop.PlatformChar
|
||||||
|
) {
|
||||||
|
guard platformString == 0 else {
|
||||||
|
fatalError(
|
||||||
|
"input of String.init(validatingPlatformString:) must be null-terminated"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
self = ""
|
||||||
|
}
|
||||||
|
|
||||||
|
@inlinable
|
||||||
|
@_alwaysEmitIntoClient
|
||||||
|
@available(*, deprecated, message: "Use a copy of the String argument")
|
||||||
|
public init?(
|
||||||
|
validatingPlatformString platformString: String
|
||||||
|
) {
|
||||||
|
if let nullLoc = platformString.firstIndex(of: "\0") {
|
||||||
|
self = String(platformString[..<nullLoc])
|
||||||
|
} else {
|
||||||
|
self = platformString
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Calls the given closure with a pointer to the contents of the string,
|
/// Calls the given closure with a pointer to the contents of the string,
|
||||||
/// represented as a null-terminated platform string.
|
/// represented as a null-terminated platform string.
|
||||||
///
|
///
|
||||||
|
|||||||
@@ -53,8 +53,8 @@ extension SystemChar {
|
|||||||
internal var isLetter: Bool {
|
internal var isLetter: Bool {
|
||||||
guard isASCII else { return false }
|
guard isASCII else { return false }
|
||||||
let asciiRaw: UInt8 = numericCast(rawValue)
|
let asciiRaw: UInt8 = numericCast(rawValue)
|
||||||
return (UInt8(ascii: "a") ..< UInt8(ascii: "z")).contains(asciiRaw) ||
|
return (UInt8(ascii: "a") ... UInt8(ascii: "z")).contains(asciiRaw) ||
|
||||||
(UInt8(ascii: "A") ..< UInt8(ascii: "Z")).contains(asciiRaw)
|
(UInt8(ascii: "A") ... UInt8(ascii: "Z")).contains(asciiRaw)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -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,42 +149,72 @@ 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>(
|
||||||
_ f: (UnsafeBufferPointer<CInterop.PlatformUnicodeEncoding.CodeUnit>) throws -> T
|
_ f: (UnsafeBufferPointer<CInterop.PlatformUnicodeEncoding.CodeUnit>) throws -> T
|
||||||
) rethrows -> T {
|
) rethrows -> T {
|
||||||
try withSystemChars {
|
try withSystemChars { chars in
|
||||||
// TODO: Is this the right way?
|
let length = chars.count * MemoryLayout<SystemChar>.stride
|
||||||
let base = UnsafeRawPointer(
|
let count = length / MemoryLayout<CInterop.PlatformUnicodeEncoding.CodeUnit>.stride
|
||||||
$0.baseAddress
|
return try chars.baseAddress!.withMemoryRebound(
|
||||||
)!.assumingMemoryBound(to: CInterop.PlatformUnicodeEncoding.CodeUnit.self)
|
to: CInterop.PlatformUnicodeEncoding.CodeUnit.self,
|
||||||
return try f(UnsafeBufferPointer(start: base, count: $0.count))
|
capacity: count
|
||||||
|
) { pointer in
|
||||||
|
try f(UnsafeBufferPointer(start: pointer, count: count))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -272,13 +310,15 @@ extension SystemString {
|
|||||||
internal func withPlatformString<T>(
|
internal func withPlatformString<T>(
|
||||||
_ f: (UnsafePointer<CInterop.PlatformChar>) throws -> T
|
_ f: (UnsafePointer<CInterop.PlatformChar>) throws -> T
|
||||||
) rethrows -> T {
|
) rethrows -> T {
|
||||||
try withSystemChars {
|
try withSystemChars { chars in
|
||||||
// TODO: Is this the right way?
|
let length = chars.count * MemoryLayout<SystemChar>.stride
|
||||||
let base = UnsafeRawPointer(
|
return try chars.baseAddress!.withMemoryRebound(
|
||||||
$0.baseAddress
|
to: CInterop.PlatformChar.self,
|
||||||
)!.assumingMemoryBound(to: CInterop.PlatformChar.self)
|
capacity: length / MemoryLayout<CInterop.PlatformChar>.stride
|
||||||
assert(base[self.count] == 0)
|
) { pointer in
|
||||||
return try f(base)
|
assert(pointer[self.count] == 0)
|
||||||
|
return try f(pointer)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,21 +8,21 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
// Results in errno if i == -1
|
// Results in errno if i == -1
|
||||||
// @available(macOS 10.16, 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, *)*/
|
||||||
private func valueOrErrno<I: FixedWidthInteger>(
|
private func valueOrErrno<I: FixedWidthInteger>(
|
||||||
_ i: I
|
_ i: I
|
||||||
) -> Result<I, Errno> {
|
) -> Result<I, Errno> {
|
||||||
i == -1 ? .failure(Errno.current) : .success(i)
|
i == -1 ? .failure(Errno.current) : .success(i)
|
||||||
}
|
}
|
||||||
|
|
||||||
// @available(macOS 10.16, 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, *)*/
|
||||||
private func nothingOrErrno<I: FixedWidthInteger>(
|
private func nothingOrErrno<I: FixedWidthInteger>(
|
||||||
_ i: I
|
_ i: I
|
||||||
) -> Result<(), Errno> {
|
) -> Result<(), Errno> {
|
||||||
valueOrErrno(i).map { _ in () }
|
valueOrErrno(i).map { _ in () }
|
||||||
}
|
}
|
||||||
|
|
||||||
// @available(macOS 10.16, 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, *)*/
|
||||||
internal func valueOrErrno<I: FixedWidthInteger>(
|
internal func valueOrErrno<I: FixedWidthInteger>(
|
||||||
retryOnInterrupt: Bool, _ f: () -> I
|
retryOnInterrupt: Bool, _ f: () -> I
|
||||||
) -> Result<I, Errno> {
|
) -> Result<I, Errno> {
|
||||||
@@ -36,7 +36,7 @@ internal func valueOrErrno<I: FixedWidthInteger>(
|
|||||||
} while true
|
} while true
|
||||||
}
|
}
|
||||||
|
|
||||||
// @available(macOS 10.16, 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, *)*/
|
||||||
internal func nothingOrErrno<I: FixedWidthInteger>(
|
internal func nothingOrErrno<I: FixedWidthInteger>(
|
||||||
retryOnInterrupt: Bool, _ f: () -> I
|
retryOnInterrupt: Bool, _ f: () -> I
|
||||||
) -> Result<(), Errno> {
|
) -> Result<(), Errno> {
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ import SystemPackage
|
|||||||
import System
|
import System
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// @available(macOS 10.16, 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, *)*/
|
||||||
final class ErrnoTest: XCTestCase {
|
final class ErrnoTest: XCTestCase {
|
||||||
func testConstants() {
|
func testConstants() {
|
||||||
XCTAssert(EPERM == Errno.notPermitted.rawValue)
|
XCTAssert(EPERM == Errno.notPermitted.rawValue)
|
||||||
@@ -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
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
/*
|
||||||
|
This source file is part of the Swift System open source project
|
||||||
|
|
||||||
|
Copyright (c) 2020 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
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if SYSTEM_PACKAGE
|
||||||
|
@testable import SystemPackage
|
||||||
|
#else
|
||||||
|
@testable import System
|
||||||
|
#endif
|
||||||
|
|
||||||
|
extension FileDescriptor {
|
||||||
|
internal func fileSize(
|
||||||
|
retryOnInterrupt: Bool = true
|
||||||
|
) throws -> Int64 {
|
||||||
|
let current = try seek(offset: 0, from: .current)
|
||||||
|
let size = try seek(offset: 0, from: .end)
|
||||||
|
try seek(offset: current, from: .start)
|
||||||
|
return size
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -15,7 +15,7 @@ import SystemPackage
|
|||||||
import System
|
import System
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// @available(macOS 10.16, 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, *)*/
|
||||||
final class FileOperationsTest: XCTestCase {
|
final class FileOperationsTest: XCTestCase {
|
||||||
func testSyscalls() {
|
func testSyscalls() {
|
||||||
let fd = FileDescriptor(rawValue: 1)
|
let fd = FileDescriptor(rawValue: 1)
|
||||||
@@ -86,9 +86,54 @@ 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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !os(Windows)
|
||||||
|
func testAdHocPipe() throws {
|
||||||
|
// Ad-hoc test testing `Pipe` functionality.
|
||||||
|
// We cannot test `Pipe` using `MockTestCase` because it calls `pipe` with a pointer to an array local to the `Pipe`, the address of which we do not know prior to invoking `Pipe`.
|
||||||
|
let pipe = try FileDescriptor.pipe()
|
||||||
|
try pipe.readEnd.closeAfter {
|
||||||
|
try pipe.writeEnd.closeAfter {
|
||||||
|
var abc = "abc"
|
||||||
|
try abc.withUTF8 {
|
||||||
|
_ = try pipe.writeEnd.write(UnsafeRawBufferPointer($0))
|
||||||
|
}
|
||||||
|
let readLen = 3
|
||||||
|
let readBytes = try Array<UInt8>(unsafeUninitializedCapacity: readLen) { buf, count in
|
||||||
|
count = try pipe.readEnd.read(into: UnsafeMutableRawBufferPointer(buf))
|
||||||
|
}
|
||||||
|
XCTAssertEqual(readBytes, Array(abc.utf8))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
func testAdHocOpen() {
|
func testAdHocOpen() {
|
||||||
// Ad-hoc test touching a file system.
|
// Ad-hoc test touching a file system.
|
||||||
@@ -139,5 +184,49 @@ final class FileOperationsTest: XCTestCase {
|
|||||||
issue26.runAllTests()
|
issue26.runAllTests()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !os(Windows)
|
||||||
|
func testResizeFile() throws {
|
||||||
|
let fd = try FileDescriptor.open("/tmp/\(UUID().uuidString).txt", .readWrite, options: [.create, .truncate], permissions: .ownerReadWrite)
|
||||||
|
try fd.closeAfter {
|
||||||
|
// File should be empty initially.
|
||||||
|
XCTAssertEqual(try fd.fileSize(), 0)
|
||||||
|
// Write 3 bytes.
|
||||||
|
try fd.writeAll("abc".utf8)
|
||||||
|
// File should now be 3 bytes.
|
||||||
|
XCTAssertEqual(try fd.fileSize(), 3)
|
||||||
|
// Resize to 6 bytes.
|
||||||
|
try fd.resize(to: 6)
|
||||||
|
// File should now be 6 bytes.
|
||||||
|
XCTAssertEqual(try fd.fileSize(), 6)
|
||||||
|
// Read in the 6 bytes.
|
||||||
|
let readBytes = try Array<UInt8>(unsafeUninitializedCapacity: 6) { (buf, count) in
|
||||||
|
try fd.seek(offset: 0, from: .start)
|
||||||
|
// Should have read all 6 bytes.
|
||||||
|
count = try fd.read(into: UnsafeMutableRawBufferPointer(buf))
|
||||||
|
XCTAssertEqual(count, 6)
|
||||||
|
}
|
||||||
|
// First 3 bytes should be unaffected by resize.
|
||||||
|
XCTAssertEqual(Array(readBytes[..<3]), Array("abc".utf8))
|
||||||
|
// Extension should be padded with zeros.
|
||||||
|
XCTAssertEqual(Array(readBytes[3...]), Array(repeating: 0, count: 3))
|
||||||
|
// File should still be 6 bytes.
|
||||||
|
XCTAssertEqual(try fd.fileSize(), 6)
|
||||||
|
// Resize to 2 bytes.
|
||||||
|
try fd.resize(to: 2)
|
||||||
|
// File should now be 2 bytes.
|
||||||
|
XCTAssertEqual(try fd.fileSize(), 2)
|
||||||
|
// Read in file with a buffer big enough for 6 bytes.
|
||||||
|
let readBytesAfterTruncation = try Array<UInt8>(unsafeUninitializedCapacity: 6) { (buf, count) in
|
||||||
|
try fd.seek(offset: 0, from: .start)
|
||||||
|
count = try fd.read(into: UnsafeMutableRawBufferPointer(buf))
|
||||||
|
// Should only have read 2 bytes.
|
||||||
|
XCTAssertEqual(count, 2)
|
||||||
|
}
|
||||||
|
// Written content was trunctated.
|
||||||
|
XCTAssertEqual(readBytesAfterTruncation, Array("ab".utf8))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -15,7 +15,7 @@ import XCTest
|
|||||||
@testable import System
|
@testable import System
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// @available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
|
/*System 0.0.2, @available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)*/
|
||||||
struct TestPathComponents: TestCase {
|
struct TestPathComponents: TestCase {
|
||||||
var path: FilePath
|
var path: FilePath
|
||||||
var expectedRoot: FilePath.Root?
|
var expectedRoot: FilePath.Root?
|
||||||
@@ -100,7 +100,7 @@ struct TestPathComponents: TestCase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// @available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
|
/*System 0.0.2, @available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)*/
|
||||||
final class FilePathComponentsTest: XCTestCase {
|
final class FilePathComponentsTest: XCTestCase {
|
||||||
func testAdHocRRC() {
|
func testAdHocRRC() {
|
||||||
var path: FilePath = "/usr/local/bin"
|
var path: FilePath = "/usr/local/bin"
|
||||||
|
|||||||
@@ -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)
|
||||||
|
))
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,7 +6,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Why can't I write this extension on `FilePath.ComponentView.SubSequence`?
|
// Why can't I write this extension on `FilePath.ComponentView.SubSequence`?
|
||||||
// @available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
|
/*System 0.0.2, @available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)*/
|
||||||
extension Slice where Base == FilePath.ComponentView {
|
extension Slice where Base == FilePath.ComponentView {
|
||||||
internal var _storageSlice: SystemString.SubSequence {
|
internal var _storageSlice: SystemString.SubSequence {
|
||||||
base._path._storage[self.startIndex._storage ..< self.endIndex._storage]
|
base._path._storage[self.startIndex._storage ..< self.endIndex._storage]
|
||||||
@@ -15,7 +15,7 @@ extension Slice where Base == FilePath.ComponentView {
|
|||||||
|
|
||||||
|
|
||||||
// Proposed API that didn't make the cut, but we stil want to keep our testing for
|
// Proposed API that didn't make the cut, but we stil want to keep our testing for
|
||||||
// @available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
|
/*System 0.0.2, @available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)*/
|
||||||
extension FilePath {
|
extension FilePath {
|
||||||
/// Returns `self` relative to `base`.
|
/// Returns `self` relative to `base`.
|
||||||
/// This does not cosult the file system or resolve symlinks.
|
/// This does not cosult the file system or resolve symlinks.
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ extension ParsingTestCase {
|
|||||||
@testable import System
|
@testable import System
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// @available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
|
/*System 0.0.2, @available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)*/
|
||||||
final class FilePathParsingTest: XCTestCase {
|
final class FilePathParsingTest: XCTestCase {
|
||||||
func testNormalization() {
|
func testNormalization() {
|
||||||
let unixPaths: Array<ParsingTestCase> = [
|
let unixPaths: Array<ParsingTestCase> = [
|
||||||
|
|||||||
@@ -146,7 +146,7 @@ extension SyntaxTestCase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// @available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
|
/*System 0.0.2, @available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)*/
|
||||||
extension SyntaxTestCase {
|
extension SyntaxTestCase {
|
||||||
func testComponents(_ path: FilePath, expected: [String]) {
|
func testComponents(_ path: FilePath, expected: [String]) {
|
||||||
let expectedComponents = expected.map { FilePath.Component($0)! }
|
let expectedComponents = expected.map { FilePath.Component($0)! }
|
||||||
@@ -342,7 +342,7 @@ private struct WindowsRootTestCase: TestCase {
|
|||||||
var line: UInt
|
var line: UInt
|
||||||
}
|
}
|
||||||
|
|
||||||
// @available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
|
/*System 0.0.2, @available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)*/
|
||||||
extension WindowsRootTestCase {
|
extension WindowsRootTestCase {
|
||||||
func runAllTests() {
|
func runAllTests() {
|
||||||
withWindowsPaths(enabled: true) {
|
withWindowsPaths(enabled: true) {
|
||||||
@@ -357,7 +357,7 @@ extension WindowsRootTestCase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// @available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
|
/*System 0.0.2, @available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)*/
|
||||||
final class FilePathSyntaxTest: XCTestCase {
|
final class FilePathSyntaxTest: XCTestCase {
|
||||||
func testPathSyntax() {
|
func testPathSyntax() {
|
||||||
let unixPaths: Array<SyntaxTestCase> = [
|
let unixPaths: Array<SyntaxTestCase> = [
|
||||||
|
|||||||
@@ -15,19 +15,21 @@ import SystemPackage
|
|||||||
import System
|
import System
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// @available(macOS 10.16, 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, *)*/
|
||||||
func filePathFromUnterminatedBytes<S: Sequence>(_ bytes: S) -> FilePath where S.Element == UInt8 {
|
func filePathFromUnterminatedBytes<S: Sequence>(_ bytes: S) -> FilePath where S.Element == UInt8 {
|
||||||
var array = Array(bytes)
|
var array = Array(bytes)
|
||||||
assert(array.last != 0, "already null terminated")
|
assert(array.last != 0, "already null terminated")
|
||||||
array += [0]
|
array += [0]
|
||||||
|
|
||||||
return array.withUnsafeBufferPointer {
|
return array.withUnsafeBufferPointer {
|
||||||
FilePath(platformString: $0.baseAddress!._asCChar)
|
$0.withMemoryRebound(to: CChar.self) {
|
||||||
|
FilePath(platformString: $0.baseAddress!)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let invalidBytes: [UInt8] = [0x2F, 0x61, 0x2F, 0x62, 0x2F, 0x83]
|
let invalidBytes: [UInt8] = [0x2F, 0x61, 0x2F, 0x62, 0x2F, 0x83]
|
||||||
|
|
||||||
// @available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
|
/*System 0.0.2, @available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)*/
|
||||||
final class FilePathTest: XCTestCase {
|
final class FilePathTest: XCTestCase {
|
||||||
struct TestPath {
|
struct TestPath {
|
||||||
let filePath: FilePath
|
let filePath: FilePath
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ import SystemPackage
|
|||||||
import System
|
import System
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// @available(macOS 10.16, 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, *)*/
|
||||||
final class FileDescriptorTest: XCTestCase {
|
final class FileDescriptorTest: XCTestCase {
|
||||||
func testStandardDescriptors() {
|
func testStandardDescriptors() {
|
||||||
XCTAssertEqual(FileDescriptor.standardInput.rawValue, 0)
|
XCTAssertEqual(FileDescriptor.standardInput.rawValue, 0)
|
||||||
@@ -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
|
||||||
@@ -60,7 +60,7 @@ final class FileDescriptorTest: XCTestCase {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// @available(macOS 10.16, 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, *)*/
|
||||||
final class FilePermissionsTest: XCTestCase {
|
final class FilePermissionsTest: XCTestCase {
|
||||||
|
|
||||||
func testPermissions() {
|
func testPermissions() {
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ import XCTest
|
|||||||
@testable import System
|
@testable import System
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// @available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
|
/*System 0.0.2, @available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)*/
|
||||||
final class MockingTest: XCTestCase {
|
final class MockingTest: XCTestCase {
|
||||||
func testMocking() {
|
func testMocking() {
|
||||||
XCTAssertFalse(mockingEnabled)
|
XCTAssertFalse(mockingEnabled)
|
||||||
|
|||||||
@@ -0,0 +1,39 @@
|
|||||||
|
/*
|
||||||
|
This source file is part of the Swift System open source project
|
||||||
|
|
||||||
|
Copyright (c) 2020 - 2021 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
|
||||||
|
|
||||||
|
final class SystemCharTest: XCTestCase {
|
||||||
|
func testIsLetter() {
|
||||||
|
let valid = SystemString(
|
||||||
|
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
|
||||||
|
for char in valid {
|
||||||
|
XCTAssertTrue(char.isLetter)
|
||||||
|
}
|
||||||
|
|
||||||
|
// non printable
|
||||||
|
for value in 0..<(UInt8(ascii: " ")) {
|
||||||
|
XCTAssertFalse(SystemChar(codeUnit: value).isLetter)
|
||||||
|
}
|
||||||
|
XCTAssertFalse(SystemChar(codeUnit: 0x7F).isLetter) // DEL
|
||||||
|
|
||||||
|
// misc other
|
||||||
|
let invalid = SystemString(
|
||||||
|
##" !"#$%&'()*+,-./0123456789:;<=>?@[\]^_`{|}~"##)
|
||||||
|
for char in invalid {
|
||||||
|
XCTAssertFalse(char.isLetter)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -10,29 +10,6 @@
|
|||||||
// Tests for PlatformString, SystemString, and FilePath's forwarding APIs
|
// Tests for PlatformString, SystemString, and FilePath's forwarding APIs
|
||||||
|
|
||||||
// TODO: Adapt test to Windows
|
// TODO: Adapt test to Windows
|
||||||
extension UnsafePointer where Pointee == UInt8 {
|
|
||||||
internal var _asCChar: UnsafePointer<CChar> {
|
|
||||||
UnsafeRawPointer(self).assumingMemoryBound(to: CChar.self)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
extension UnsafePointer where Pointee == CChar {
|
|
||||||
internal var _asUInt8: UnsafePointer<UInt8> {
|
|
||||||
UnsafeRawPointer(self).assumingMemoryBound(to: UInt8.self)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
extension UnsafeBufferPointer where Element == UInt8 {
|
|
||||||
internal var _asCChar: UnsafeBufferPointer<CChar> {
|
|
||||||
let base = baseAddress?._asCChar
|
|
||||||
return UnsafeBufferPointer<CChar>(start: base, count: self.count)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
extension UnsafeBufferPointer where Element == CChar {
|
|
||||||
internal var _asUInt8: UnsafeBufferPointer<UInt8> {
|
|
||||||
let base = baseAddress?._asUInt8
|
|
||||||
return UnsafeBufferPointer<UInt8>(start: base, count: self.count)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
import XCTest
|
import XCTest
|
||||||
|
|
||||||
@@ -46,7 +23,7 @@ private func makeRaw(
|
|||||||
_ str: String
|
_ str: String
|
||||||
) -> [CInterop.PlatformChar] {
|
) -> [CInterop.PlatformChar] {
|
||||||
var str = str
|
var str = str
|
||||||
var array = str.withUTF8 { Array($0._asCChar) }
|
var array = str.withUTF8 { $0.withMemoryRebound(to: CChar.self, Array.init) }
|
||||||
array.append(0)
|
array.append(0)
|
||||||
return array
|
return array
|
||||||
}
|
}
|
||||||
@@ -275,3 +252,165 @@ final class SystemStringTest: XCTestCase {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extension SystemStringTest {
|
||||||
|
func test_String_initWithArrayConversion() {
|
||||||
|
let source: [CInterop.PlatformChar] = [0x61, 0x62, 0, 0x63]
|
||||||
|
let str = String(platformString: source)
|
||||||
|
source.withUnsafeBufferPointer {
|
||||||
|
XCTAssertEqual(str, String(platformString: $0.baseAddress!))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@available(*, deprecated) // silence the warning for using a deprecated api
|
||||||
|
func test_String_initWithStringConversion() {
|
||||||
|
let source = "ab\0c"
|
||||||
|
var str: String
|
||||||
|
str = String(platformString: source)
|
||||||
|
source.withPlatformString {
|
||||||
|
XCTAssertEqual(str, String(platformString: $0))
|
||||||
|
}
|
||||||
|
str = String(platformString: "")
|
||||||
|
XCTAssertEqual(str.isEmpty, true)
|
||||||
|
}
|
||||||
|
|
||||||
|
@available(*, deprecated) // silence the warning for using a deprecated api
|
||||||
|
func test_String_initWithInoutConversion() {
|
||||||
|
var c: CInterop.PlatformChar = 0
|
||||||
|
let str = String(platformString: &c)
|
||||||
|
// Any other value of `c` would violate the null-terminated precondition
|
||||||
|
XCTAssertEqual(str.isEmpty, true)
|
||||||
|
}
|
||||||
|
|
||||||
|
func test_String_validatingPlatformStringWithArrayConversion() {
|
||||||
|
var source: [CInterop.PlatformChar] = [0x61, 0x62, 0, 0x63]
|
||||||
|
var str: String?
|
||||||
|
str = String(validatingPlatformString: source)
|
||||||
|
source.withUnsafeBufferPointer {
|
||||||
|
XCTAssertEqual(str, String(validatingPlatformString: $0.baseAddress!))
|
||||||
|
}
|
||||||
|
source[1] = CInterop.PlatformChar(truncatingIfNeeded: 0xffff)
|
||||||
|
str = String(validatingPlatformString: source)
|
||||||
|
XCTAssertNil(str)
|
||||||
|
}
|
||||||
|
|
||||||
|
@available(*, deprecated) // silence the warning for using a deprecated api
|
||||||
|
func test_String_validatingPlatformStringWithStringConversion() {
|
||||||
|
let source = "ab\0c"
|
||||||
|
var str: String?
|
||||||
|
str = String(validatingPlatformString: source)
|
||||||
|
XCTAssertNotNil(str)
|
||||||
|
source.withPlatformString {
|
||||||
|
XCTAssertEqual(str, String.init(validatingPlatformString: $0))
|
||||||
|
}
|
||||||
|
str = String(validatingPlatformString: "")
|
||||||
|
XCTAssertNotNil(str)
|
||||||
|
XCTAssertEqual(str?.isEmpty, true)
|
||||||
|
}
|
||||||
|
|
||||||
|
@available(*, deprecated) // silence the warning for using a deprecated api
|
||||||
|
func test_String_validatingPlatformStringWithInoutConversion() {
|
||||||
|
var c: CInterop.PlatformChar = 0
|
||||||
|
let str = String(validatingPlatformString: &c)
|
||||||
|
// Any other value of `c` would violate the null-terminated precondition
|
||||||
|
XCTAssertNotNil(str)
|
||||||
|
XCTAssertEqual(str?.isEmpty, true)
|
||||||
|
}
|
||||||
|
|
||||||
|
func test_FilePath_initWithArrayConversion() {
|
||||||
|
let source: [CInterop.PlatformChar] = [0x61, 0x62, 0, 0x63]
|
||||||
|
let path = FilePath(platformString: source)
|
||||||
|
source.withUnsafeBufferPointer {
|
||||||
|
XCTAssertEqual(path, FilePath(platformString: $0.baseAddress!))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@available(*, deprecated) // silence the warning for using a deprecated api
|
||||||
|
func test_FilePath_initWithStringConversion() {
|
||||||
|
let source = "ab\0c"
|
||||||
|
var path: FilePath
|
||||||
|
path = FilePath(platformString: source)
|
||||||
|
source.withPlatformString {
|
||||||
|
XCTAssertEqual(path, FilePath(platformString: $0))
|
||||||
|
}
|
||||||
|
path = FilePath(platformString: "")
|
||||||
|
XCTAssertEqual(path.string.isEmpty, true)
|
||||||
|
}
|
||||||
|
|
||||||
|
@available(*, deprecated) // silence the warning for using a deprecated api
|
||||||
|
func test_FilePath_initWithInoutConversion() {
|
||||||
|
var c: CInterop.PlatformChar = 0
|
||||||
|
let path = FilePath(platformString: &c)
|
||||||
|
// Any other value of `c` would violate the null-terminated precondition
|
||||||
|
XCTAssertEqual(path.string.isEmpty, true)
|
||||||
|
}
|
||||||
|
|
||||||
|
func test_FilePathComponent_initWithArrayConversion() {
|
||||||
|
var source: [CInterop.PlatformChar] = [0x61, 0x62, 0, 0x63]
|
||||||
|
var component: FilePath.Component?
|
||||||
|
component = FilePath.Component(platformString: source)
|
||||||
|
source.withUnsafeBufferPointer {
|
||||||
|
XCTAssertEqual(component, .init(platformString: $0.baseAddress!))
|
||||||
|
}
|
||||||
|
source[1] = CInterop.PlatformChar(truncatingIfNeeded: 0xffff)
|
||||||
|
component = FilePath.Component(platformString: source)
|
||||||
|
source.withUnsafeBufferPointer {
|
||||||
|
XCTAssertEqual(component, .init(platformString: $0.baseAddress!))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@available(*, deprecated) // silence the warning for using a deprecated api
|
||||||
|
func test_FilePathComponent_initWithStringConversion() {
|
||||||
|
let source = "ab\0c"
|
||||||
|
var component: FilePath.Component?
|
||||||
|
component = FilePath.Component(platformString: source)
|
||||||
|
source.withPlatformString {
|
||||||
|
XCTAssertEqual(component, FilePath.Component(platformString: $0))
|
||||||
|
}
|
||||||
|
component = FilePath.Component(platformString: "")
|
||||||
|
XCTAssertNil(component)
|
||||||
|
}
|
||||||
|
|
||||||
|
@available(*, deprecated) // silence the warning for using a deprecated api
|
||||||
|
func test_FilePathComponent_initWithInoutConversion() {
|
||||||
|
var c: CInterop.PlatformChar = 0
|
||||||
|
let component = FilePath.Component(platformString: &c)
|
||||||
|
XCTAssertNil(component)
|
||||||
|
}
|
||||||
|
|
||||||
|
func test_FilePathRoot_initWithArrayConversion() {
|
||||||
|
let source: [CInterop.PlatformChar]
|
||||||
|
#if os(Windows)
|
||||||
|
source = [0x41, 0x3a, 0x5c, 0, 0x7f]
|
||||||
|
#else // unix
|
||||||
|
source = [0x2f, 0, 0x7f]
|
||||||
|
#endif
|
||||||
|
var root: FilePath.Root?
|
||||||
|
root = FilePath.Root(platformString: source)
|
||||||
|
source.withUnsafeBufferPointer {
|
||||||
|
XCTAssertEqual(root, FilePath.Root(platformString: $0.baseAddress!))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@available(*, deprecated) // silence the warning for using a deprecated api
|
||||||
|
func test_FilePathRoot_initWithStringConversion() {
|
||||||
|
#if os(Windows)
|
||||||
|
let source = "C:\\\0 and the rest"
|
||||||
|
#else // unix
|
||||||
|
let source = "/\0 and the rest"
|
||||||
|
#endif
|
||||||
|
var root: FilePath.Root?
|
||||||
|
root = FilePath.Root(platformString: source)
|
||||||
|
source.withPlatformString {
|
||||||
|
XCTAssertEqual(root, FilePath.Root(platformString: $0))
|
||||||
|
}
|
||||||
|
root = FilePath.Root(platformString: "")
|
||||||
|
XCTAssertNil(root)
|
||||||
|
}
|
||||||
|
|
||||||
|
@available(*, deprecated) // silence the warning for using a deprecated api
|
||||||
|
func test_FilePathRoot_initWithInoutConversion() {
|
||||||
|
var c: CInterop.PlatformChar = 0
|
||||||
|
let root = FilePath.Root(platformString: &c)
|
||||||
|
XCTAssertNil(root)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -27,6 +27,7 @@ extension FileOperationsTest {
|
|||||||
// to regenerate.
|
// to regenerate.
|
||||||
static let __allTests__FileOperationsTest = [
|
static let __allTests__FileOperationsTest = [
|
||||||
("testAdHocOpen", testAdHocOpen),
|
("testAdHocOpen", testAdHocOpen),
|
||||||
|
("testAdHocPipe", testAdHocPipe),
|
||||||
("testGithubIssues", testGithubIssues),
|
("testGithubIssues", testGithubIssues),
|
||||||
("testHelpers", testHelpers),
|
("testHelpers", testHelpers),
|
||||||
("testSyscalls", testSyscalls),
|
("testSyscalls", testSyscalls),
|
||||||
@@ -94,6 +95,15 @@ extension MockingTest {
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extension SystemCharTest {
|
||||||
|
// DO NOT MODIFY: This is autogenerated, use:
|
||||||
|
// `swift test --generate-linuxmain`
|
||||||
|
// to regenerate.
|
||||||
|
static let __allTests__SystemCharTest = [
|
||||||
|
("testIsLetter", testIsLetter),
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
extension SystemStringTest {
|
extension SystemStringTest {
|
||||||
// DO NOT MODIFY: This is autogenerated, use:
|
// DO NOT MODIFY: This is autogenerated, use:
|
||||||
// `swift test --generate-linuxmain`
|
// `swift test --generate-linuxmain`
|
||||||
@@ -115,6 +125,7 @@ public func __allTests() -> [XCTestCaseEntry] {
|
|||||||
testCase(FilePathTest.__allTests__FilePathTest),
|
testCase(FilePathTest.__allTests__FilePathTest),
|
||||||
testCase(FilePermissionsTest.__allTests__FilePermissionsTest),
|
testCase(FilePermissionsTest.__allTests__FilePermissionsTest),
|
||||||
testCase(MockingTest.__allTests__MockingTest),
|
testCase(MockingTest.__allTests__MockingTest),
|
||||||
|
testCase(SystemCharTest.__allTests__SystemCharTest),
|
||||||
testCase(SystemStringTest.__allTests__SystemStringTest),
|
testCase(SystemStringTest.__allTests__SystemStringTest),
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
Executable
+85
@@ -0,0 +1,85 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
# This script can be used to automatically add/remove `@available` attributes to
|
||||||
|
# declarations in Swift sources in this package.
|
||||||
|
#
|
||||||
|
# In order for this to work, ABI-impacting declarations need to be annotated
|
||||||
|
# with special comments in the following format:
|
||||||
|
#
|
||||||
|
# /*System 0.0.2*/
|
||||||
|
# public func greeting() -> String {
|
||||||
|
# "Hello"
|
||||||
|
# }
|
||||||
|
#
|
||||||
|
# The script adds full availability incantations to these comments. It can run
|
||||||
|
# in one of two modes:
|
||||||
|
#
|
||||||
|
# By default, `expand-availability.py` expands availability macros within the
|
||||||
|
# comments. This is useful during package development to cross-reference
|
||||||
|
# availability across `SystemPackage` and the ABI-stable `System` module that
|
||||||
|
# ships in Apple's OS releases:
|
||||||
|
#
|
||||||
|
# /*System 0.0.2, @available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)*/
|
||||||
|
# public func greeting() -> String {
|
||||||
|
# "Hello"
|
||||||
|
# }
|
||||||
|
#
|
||||||
|
# `expand-availability.py --attributes` adds actual availability attributes.
|
||||||
|
# This is used by maintainers to build ABI stable releases of System on Apple's
|
||||||
|
# platforms:
|
||||||
|
#
|
||||||
|
# /*System 0.0.2*/@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
|
||||||
|
# public func greeting() -> String {
|
||||||
|
# "Hello"
|
||||||
|
# }
|
||||||
|
#
|
||||||
|
# The script recognizes all three forms of these annotations and updates them on
|
||||||
|
# every run, so we can run the script to enable/disable attributes as needed.
|
||||||
|
|
||||||
|
import os
|
||||||
|
import os.path
|
||||||
|
import fileinput
|
||||||
|
import re
|
||||||
|
import sys
|
||||||
|
import argparse
|
||||||
|
|
||||||
|
versions = {
|
||||||
|
"System 0.0.1": "macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0",
|
||||||
|
"System 0.0.2": "macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0",
|
||||||
|
"System 1.1.0": "macOS 9999, iOS 9999, watchOS 9999, tvOS 9999",
|
||||||
|
"System 1.2.0": "macOS 9999, iOS 9999, watchOS 9999, tvOS 9999",
|
||||||
|
}
|
||||||
|
|
||||||
|
parser = argparse.ArgumentParser(description="Expand availability macros.")
|
||||||
|
parser.add_argument("--attributes", help="Add @available attributes",
|
||||||
|
action="store_true")
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
def swift_sources_in(path):
|
||||||
|
result = []
|
||||||
|
for (dir, _, files) in os.walk(path):
|
||||||
|
for file in files:
|
||||||
|
extension = os.path.splitext(file)[1]
|
||||||
|
if extension == ".swift":
|
||||||
|
result.append(os.path.join(dir, file))
|
||||||
|
return result
|
||||||
|
|
||||||
|
macro_pattern = re.compile(
|
||||||
|
r"/\*(System [^ *]+)(, @available\([^)]*\))?\*/(@available\([^)]*\))?")
|
||||||
|
|
||||||
|
sources = swift_sources_in("Sources") + swift_sources_in("Tests")
|
||||||
|
for line in fileinput.input(files=sources, inplace=True):
|
||||||
|
match = re.search(macro_pattern, line)
|
||||||
|
if match:
|
||||||
|
system_version = match.group(1)
|
||||||
|
expansion = versions[system_version]
|
||||||
|
if expansion is None:
|
||||||
|
raise ValueError("{0}:{1}: error: Unknown System version '{0}'"
|
||||||
|
.format(fileinput.filename(), fileinput.lineno(),
|
||||||
|
system_version))
|
||||||
|
if args.attributes:
|
||||||
|
replacement = "/*{0}*/@available({1}, *)".format(system_version, expansion)
|
||||||
|
else:
|
||||||
|
replacement = "/*{0}, @available({1}, *)*/".format(system_version, expansion)
|
||||||
|
line = line[:match.start()] + replacement + line[match.end():]
|
||||||
|
print(line, end="")
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
#[[
|
||||||
|
This source file is part of the Swift System open source Project
|
||||||
|
|
||||||
|
Copyright (c) 2021 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
|
||||||
|
#]]
|
||||||
|
|
||||||
|
set(SWIFT_SYSTEM_EXPORTS_FILE ${CMAKE_CURRENT_BINARY_DIR}/SwiftSystemExports.cmake)
|
||||||
|
|
||||||
|
configure_file(SwiftSystemConfig.cmake.in
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/SwiftSystemConfig.cmake)
|
||||||
|
|
||||||
|
get_property(SWIFT_SYSTEM_EXPORTS GLOBAL PROPERTY SWIFT_SYSTEM_EXPORTS)
|
||||||
|
export(TARGETS ${SWIFT_SYSTEM_EXPORTS}
|
||||||
|
NAMESPACE SwiftSystem::
|
||||||
|
FILE ${SWIFT_SYSTEM_EXPORTS_FILE}
|
||||||
|
EXPORT_LINK_INTERFACE_LIBRARIES)
|
||||||
@@ -17,8 +17,12 @@ 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}" STREQUAL "aarch64")
|
elseif ("${CMAKE_SYSTEM_PROCESSOR}" MATCHES "AArch64|aarch64|arm64|ARM64")
|
||||||
set("${result_var_name}" "aarch64" PARENT_SCOPE)
|
if(CMAKE_SYSTEM_NAME MATCHES Darwin)
|
||||||
|
set("${result_var_name}" "arm64" PARENT_SCOPE)
|
||||||
|
else()
|
||||||
|
set("${result_var_name}" "aarch64" PARENT_SCOPE)
|
||||||
|
endif()
|
||||||
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "ppc64")
|
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "ppc64")
|
||||||
set("${result_var_name}" "powerpc64" PARENT_SCOPE)
|
set("${result_var_name}" "powerpc64" PARENT_SCOPE)
|
||||||
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "ppc64le")
|
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "ppc64le")
|
||||||
@@ -31,6 +35,8 @@ function(get_swift_host_arch result_var_name)
|
|||||||
set("${result_var_name}" "armv7" PARENT_SCOPE)
|
set("${result_var_name}" "armv7" PARENT_SCOPE)
|
||||||
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "armv7-a")
|
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "armv7-a")
|
||||||
set("${result_var_name}" "armv7" PARENT_SCOPE)
|
set("${result_var_name}" "armv7" PARENT_SCOPE)
|
||||||
|
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "amd64")
|
||||||
|
set("${result_var_name}" "amd64" PARENT_SCOPE)
|
||||||
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "AMD64")
|
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "AMD64")
|
||||||
set("${result_var_name}" "x86_64" PARENT_SCOPE)
|
set("${result_var_name}" "x86_64" PARENT_SCOPE)
|
||||||
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "IA64")
|
elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "IA64")
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
#[[
|
||||||
|
This source file is part of the Swift System open source Project
|
||||||
|
|
||||||
|
Copyright (c) 2021 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
|
||||||
|
#]]
|
||||||
|
|
||||||
|
if(NOT TARGET SystemPackage)
|
||||||
|
include(@SWIFT_SYSTEM_EXPORTS_FILE@)
|
||||||
|
endif()
|
||||||
Reference in new issue
Block a user