[libcxx-commits] [libcxx] [libc++][streams] P1759R6: Native handles and file streams (PR #76632)

Hristo Hristov via libcxx-commits libcxx-commits at lists.llvm.org
Sun Dec 31 01:30:30 PST 2023


================
@@ -208,8 +216,37 @@ _LIBCPP_PUSH_MACROS
 
 #if !defined(_LIBCPP_HAS_NO_FILESYSTEM)
 
+#  if defined(_LIBCPP_WIN32API)
+#    define WIN32_LEAN_AND_MEAN
+#    define NOMINMAX
+#    include <io.h>
+#    include <windows.h>
+#  endif
+
+#include <fcntl.h>
+
 _LIBCPP_BEGIN_NAMESPACE_STD
 
+#  if _LIBCPP_STD_VER >= 26
+#    if defined(_LIBCPP_WIN32API)
+using __filebuf_native_handle_type = void*; // HANDLE
+#    else
+using __filebuf_native_handle_type = int; // POSIX file descriptor
+#    endif
+_LIBCPP_HIDE_FROM_ABI __filebuf_native_handle_type __filebuf_native_handle(FILE* __file) noexcept;
+__filebuf_native_handle_type __filebuf_native_handle(FILE* __file) noexcept {
+#    if defined(_LIBCPP_WIN32API)
+  // https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/get-osfhandle?view=msvc-170
+  intptr_t __handle = _get_osfhandle(::fileno(__file));
+  if (__handle == -1)
+    return nullptr;
+  return reinterpret_cast<void*>(__handle);
+#    else
+  return ::fileno(__file);
+#    endif
+}
+#  endif
----------------
H-G-Hristov wrote:



This should be moved out... (just for testing).


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


More information about the libcxx-commits mailing list