[clang] [lld] [llvm] [flang] [libcxx] [libc++][streams] P1759R6: Native handles and file streams (PR #76632)

Hristo Hristov via cfe-commits cfe-commits at lists.llvm.org
Sun Dec 31 23:21:24 PST 2023


================
@@ -208,8 +215,34 @@ _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 = HANDLE;
+_LIBCPP_EXPORTED_FROM_ABI __filebuf_native_handle_type __filebuf_windows_native_handle(FILE* __file);
+#    else // POSIX
+using __filebuf_native_handle_type = int; // File descriptor
+#    endif
+
+_LIBCPP_HIDE_FROM_ABI inline __filebuf_native_handle_type __filebuf_native_handle(FILE* __file) noexcept {
+#    if defined(_LIBCPP_WIN32API)
+  return __filebuf_windows_native_handle(__file);
+#    else
+  return ::fileno(__file);
+#    endif
+}
+#  endif
+
----------------
H-G-Hristov wrote:

Great tip! Thank you!

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


More information about the cfe-commits mailing list