diff options
author | Hristo Hristov <hristo.goshev.hristov@gmail.com> | 2024-01-07 18:01:03 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-07 18:01:03 +0200 |
commit | 92e243173c09fc78c25814a7d7e392971034f5be (patch) | |
tree | b564429a1680530332731b5a7bb45affb277bfce /libcxx/src | |
parent | 535d8e8b92e3f8cf4107d9431012310c9a72c8d3 (diff) | |
download | llvm-92e243173c09fc78c25814a7d7e392971034f5be.zip llvm-92e243173c09fc78c25814a7d7e392971034f5be.tar.gz llvm-92e243173c09fc78c25814a7d7e392971034f5be.tar.bz2 |
Reapply "[libc++][streams] P1759R6: Native handles and file streams" (#77190)
Fixes build on Windows in C++26 mode.
Reverted in:
https://github.com/llvm/llvm-project/commit/40c07b559aa6ab4bac074c943967d3207bc07ae0
Original PR: https://github.com/llvm/llvm-project/pull/76632
---------
Co-authored-by: Zingam <zingam@outlook.com>
Diffstat (limited to 'libcxx/src')
-rw-r--r-- | libcxx/src/CMakeLists.txt | 1 | ||||
-rw-r--r-- | libcxx/src/fstream.cpp | 37 |
2 files changed, 38 insertions, 0 deletions
diff --git a/libcxx/src/CMakeLists.txt b/libcxx/src/CMakeLists.txt index 329964a..96e7c63 100644 --- a/libcxx/src/CMakeLists.txt +++ b/libcxx/src/CMakeLists.txt @@ -84,6 +84,7 @@ endif() if (LIBCXX_ENABLE_LOCALIZATION) list(APPEND LIBCXX_SOURCES + fstream.cpp include/sso_allocator.h ios.cpp ios.instantiations.cpp diff --git a/libcxx/src/fstream.cpp b/libcxx/src/fstream.cpp new file mode 100644 index 0000000..55a4442 --- /dev/null +++ b/libcxx/src/fstream.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +#include <__config> +#include <cstdio> +#include <fstream> + +#if defined(_LIBCPP_WIN32API) +# define WIN32_LEAN_AND_MEAN +# define NOMINMAX +# include <io.h> +# include <windows.h> +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +#if defined(_LIBCPP_WIN32API) + +// Confirm that `HANDLE` is `void*` as implemented in `basic_filebuf` +static_assert(std::same_as<HANDLE, void*>); + +_LIBCPP_EXPORTED_FROM_ABI void* __filebuf_windows_native_handle(FILE* __file) noexcept { + // 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); +} + +#endif + +_LIBCPP_END_NAMESPACE_STD |