Vendor import of llvm-project branch release/19.x llvmorg-19.1.1-0-gd401987fe349...
[freebsd/src.git] / libcxx / src / fstream.cpp
blob55a4442b9c782224e68c6d464825ecf55ddae0bd
1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #include <__config>
10 #include <cstdio>
11 #include <fstream>
13 #if defined(_LIBCPP_WIN32API)
14 # define WIN32_LEAN_AND_MEAN
15 # define NOMINMAX
16 # include <io.h>
17 # include <windows.h>
18 #endif
20 _LIBCPP_BEGIN_NAMESPACE_STD
22 #if defined(_LIBCPP_WIN32API)
24 // Confirm that `HANDLE` is `void*` as implemented in `basic_filebuf`
25 static_assert(std::same_as<HANDLE, void*>);
27 _LIBCPP_EXPORTED_FROM_ABI void* __filebuf_windows_native_handle(FILE* __file) noexcept {
28 // https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/get-osfhandle?view=msvc-170
29 intptr_t __handle = _get_osfhandle(fileno(__file));
30 if (__handle == -1)
31 return nullptr;
32 return reinterpret_cast<void*>(__handle);
35 #endif
37 _LIBCPP_END_NAMESPACE_STD