mirror of
https://github.com/apple/swift-system
synced 2026-11-26 04:57:54 +00:00
Add symbolic names for standard file descriptors
This commit is contained in:
1 parent
5bea53afe7
commit
2904f9ead3
2 files changed
+23
-2
No files matched your search
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
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 - 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
|
||||
@@ -25,6 +25,21 @@ public struct FileDescriptor: RawRepresentable, Hashable, Codable {
|
||||
public init(rawValue: CInt) { self.rawValue = rawValue }
|
||||
}
|
||||
|
||||
// Standard file descriptors
|
||||
extension FileDescriptor {
|
||||
/// The standard input file descriptor, with a numeric value of 0.
|
||||
@_alwaysEmitIntoClient
|
||||
public static var standardInput: FileDescriptor { .init(rawValue: 0) }
|
||||
|
||||
/// The standard output file descriptor, with a numeric value of 1.
|
||||
@_alwaysEmitIntoClient
|
||||
public static var standardOutput: FileDescriptor { .init(rawValue: 1) }
|
||||
|
||||
/// The standard error file descriptor, with a numeric value of 2.
|
||||
@_alwaysEmitIntoClient
|
||||
public static var standardError: FileDescriptor { .init(rawValue: 2) }
|
||||
}
|
||||
|
||||
// @available(macOS 10.16, iOS 14.0, watchOS 7.0, tvOS 14.0, *)
|
||||
extension FileDescriptor {
|
||||
/// The desired read and write access for a newly opened file.
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
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 - 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
|
||||
@@ -12,6 +12,12 @@ import SystemPackage
|
||||
|
||||
// @available(macOS 10.16, iOS 14.0, watchOS 7.0, tvOS 14.0, *)
|
||||
final class FileDescriptorTest: XCTestCase {
|
||||
func testStandardDescriptors() {
|
||||
XCTAssertEqual(FileDescriptor.standardInput.rawValue, 0)
|
||||
XCTAssertEqual(FileDescriptor.standardOutput.rawValue, 1)
|
||||
XCTAssertEqual(FileDescriptor.standardError.rawValue, 2)
|
||||
}
|
||||
|
||||
// Test the constants match the C header values. For various reasons,
|
||||
func testConstants() {
|
||||
XCTAssertEqual(O_RDONLY, FileDescriptor.AccessMode.readOnly.rawValue)
|
||||
|
||||
Reference in new issue
Block a user