[Lldb-commits] [lldb] [llvm] [lldb][windows] use Windows APIs to print to the console (PR #149493)

Saleem Abdulrasool via lldb-commits lldb-commits at lists.llvm.org
Thu Jul 24 11:33:15 PDT 2025


================
@@ -247,6 +248,28 @@ uint32_t File::GetPermissions(Status &error) const {
   return file_stats.st_mode & (S_IRWXU | S_IRWXG | S_IRWXO);
 }
 
+NativeFile::NativeFile()
+    : m_descriptor(kInvalidDescriptor), m_stream(kInvalidStream) {}
+
+NativeFile::NativeFile(FILE *fh, bool transfer_ownership)
+    : m_descriptor(kInvalidDescriptor), m_own_descriptor(false), m_stream(fh),
+      m_options(), m_own_stream(transfer_ownership) {
+#ifdef _WIN32
+  int fd = _fileno(fh);
+  is_windows_console =
+      ::GetFileType((HANDLE)::_get_osfhandle(fd)) == FILE_TYPE_CHAR;
+#endif
+}
+
+NativeFile::NativeFile(int fd, OpenOptions options, bool transfer_ownership)
+    : m_descriptor(fd), m_own_descriptor(transfer_ownership),
+      m_stream(kInvalidStream), m_options(options), m_own_stream(false) {
+#ifdef _WIN32
+  is_windows_console =
+      ::GetFileType((HANDLE)::_get_osfhandle(fd)) == FILE_TYPE_CHAR;
+#endif
+}
----------------
compnerd wrote:

Can you not just delegate to the fd constructor? Simply inline the `_fileno` call in the delegation.

https://github.com/llvm/llvm-project/pull/149493


More information about the lldb-commits mailing list