StandardErrorOutputStream.swift 736 B

123456789101112131415161718192021222324
  1. // Sources/SwiftProtobufPluginLibrary/StandardErrorOutputStream.swift
  2. //
  3. // Copyright (c) 2014 - 2023 Apple Inc. and the project authors
  4. // Licensed under Apache License v2.0 with Runtime Library Exception
  5. //
  6. // See LICENSE.txt for license information:
  7. // https://github.com/apple/swift-protobuf/blob/main/LICENSE.txt
  8. //
  9. import Foundation
  10. class StandardErrorOutputStream: TextOutputStream {
  11. func write(_ string: String) {
  12. #if swift(>=5.1)
  13. if #available(macOS 10.15.4, iOS 13.4, watchOS 6.2, tvOS 13.4, *) {
  14. try! FileHandle.standardError.write(contentsOf: Data(string.utf8))
  15. } else {
  16. FileHandle.standardError.write(Data(string.utf8))
  17. }
  18. #else
  19. FileHandle.standardError.write(Data(string.utf8))
  20. #endif
  21. }
  22. }