From 3be2ba0ba38a1799d937a0ef302fb792d12d75a8 Mon Sep 17 00:00:00 2001 From: Abhina Sreeskantharajan Date: Fri, 16 Apr 2021 08:06:35 -0400 Subject: [SystemZ][z/OS][Windows] Add new functions that set Text/Binary mode for Stdin and Stdout based on OpenFlags On Windows, we want to open a file in Binary mode if OF_CRLF bit is not set. On z/OS, we want to open a file in Binary mode if the OF_Text bit is not set. This patch creates two new functions called ChangeStdinMode and ChangeStdoutMode which will take OpenFlags as an arg to determine which mode to set stdin and stdout to. This will enable patches like https://reviews.llvm.org/D100056 to not affect Windows when setting the OF_Text flag for raw_fd_streams. Reviewed By: rnk Differential Revision: https://reviews.llvm.org/D100130 --- llvm/lib/Support/Unix/Program.inc | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'llvm/lib/Support/Unix/Program.inc') diff --git a/llvm/lib/Support/Unix/Program.inc b/llvm/lib/Support/Unix/Program.inc index 3f18d89..be59bb0 100644 --- a/llvm/lib/Support/Unix/Program.inc +++ b/llvm/lib/Support/Unix/Program.inc @@ -493,6 +493,18 @@ ProcessInfo llvm::sys::Wait(const ProcessInfo &PI, unsigned SecondsToWait, return WaitResult; } +std::error_code llvm::sys::ChangeStdinMode(fs::OpenFlags Flags){ + if (!(Flags & fs::OF_Text)) + return ChangeStdinToBinary(); + return std::error_code(); +} + +std::error_code llvm::sys::ChangeStdoutMode(fs::OpenFlags Flags){ + if (!(Flags & fs::OF_Text)) + return ChangeStdoutToBinary(); + return std::error_code(); +} + std::error_code llvm::sys::ChangeStdinToBinary() { // Do nothing, as Unix doesn't differentiate between text and binary. return std::error_code(); -- cgit v1.1