================
@@ -143,6 +148,73 @@ static void PrintVersion() {
   llvm::outs() << "liblldb: " << lldb::SBDebugger::GetVersionString() << '\n';
 }
 
+#if not defined(_WIN32)
+struct FDGroup {
+  std::vector<int> fds;
+  bool read = false;
+  bool write = false;
+};
+
+static llvm::Error RedirectToFile(const FDGroup &fdg, llvm::StringRef file) {
+  if (!fdg.read && !fdg.write)
+    return llvm::Error::success();
+  int flags = 0;
+  if (fdg.read && fdg.write)
+    flags = O_NOCTTY | O_CREAT | O_RDWR;
+  else if (fdg.read)
+    flags = O_NOCTTY | O_RDONLY;
+  else
+    flags = O_NOCTTY | O_CREAT | O_WRONLY | O_TRUNC;
----------------
JDevlieghere wrote:

Maybe consider making this `FDGroup::GetFlags()` and have some early returns to 
avoid all the else cases? Something like:

```
int GetFlags() const {
  if (fdg.read && fdg.write)
    return O_NOCTTY | O_CREAT | O_RDWR;
  if (fdg.read)
    return O_NOCTTY | O_RDONLY;
  return O_NOCTTY | O_CREAT | O_WRONLY | O_TRUNC;
} 
``` 

https://github.com/llvm/llvm-project/pull/161089
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to