[flang-commits] [flang] [lld] [llvm] [libcxx] [clang] [libc++][streams] P1759R6: Native handles and file streams (PR #76632)
Mark de Wever via flang-commits
flang-commits at lists.llvm.org
Tue Jan 2 09:11:51 PST 2024
================
@@ -0,0 +1,81 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef TEST_STD_INPUT_OUTPUT_FILE_STREAMS_FSTREAMS_TEST_HELPERS_H
+#define TEST_STD_INPUT_OUTPUT_FILE_STREAMS_FSTREAMS_TEST_HELPERS_H
+
+#if _LIBCPP_STD_VER >= 26
+
+# include <cassert>
+# include <concepts>
+# include <cstdio>
+# include <fstream>
+# include <filesystem>
+# include <type_traits>
+# include <utility>
+
+# if defined(_LIBCPP_WIN32API)
+# define WIN32_LEAN_AND_MEAN
+# define NOMINMAX
+# include <io.h>
+# include <windows.h>
+# else
+# include <fcntl.h>
+# endif
+
+# include "platform_support.h"
+
+# if defined(_LIBCPP_WIN32API)
+using HandleT = void*; // HANDLE
+
+bool is_handle_valid(void* handle) {
+ if (BY_HANDLE_FILE_INFORMATION fileInformation; !GetFileInformationByHandle(handle, &fileInformation))
+ return false;
+ return true;
+};
+# elif __has_include(<unistd.h>) // POSIX
+using HandleT = int; // POSIX file descriptor
+
+bool is_handle_valid(HandleT fd) { return fcntl(fd, F_GETFL) != -1 || errno != EBADF; };
+# else
+# error "Provide a native file handle!"
+# endif
+
+template <typename CharT, typename StreamT>
+void test_native_handle() {
+ static_assert(
+ std::is_same_v<typename std::basic_filebuf<CharT>::native_handle_type, typename StreamT::native_handle_type>);
+
+ HandleT native_handle{};
----------------
mordante wrote:
Please apply the comments to the filebuf test here too.
https://github.com/llvm/llvm-project/pull/76632
More information about the flang-commits
mailing list